* 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

View file

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