* Don't allocate more than SIZE_MAX bytes.

This commit is contained in:
Eelco Dolstra 2006-09-22 11:13:35 +00:00
parent 4cab35d1a6
commit b43aeadbc9
1 changed files with 7 additions and 0 deletions

View File

@ -1,3 +1,5 @@
#define __STDC_LIMIT_MACROS
#include "references.hh"
#include "hash.hh"
#include "util.hh"
@ -11,6 +13,8 @@
#include <dirent.h>
#include <fcntl.h>
#include <stdint.h>
namespace nix {
@ -76,6 +80,9 @@ void checkPath(const string & path,
AutoCloseFD fd = open(path.c_str(), O_RDONLY);
if (fd == -1) throw SysError(format("opening file `%1%'") % path);
if (st.st_size >= SIZE_MAX)
throw Error(format("cannot allocate %1% bytes") % st.st_size);
unsigned char * buf = new unsigned char[st.st_size];
readFull(fd, buf, st.st_size);