diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-09-22 11:13:35 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-09-22 11:13:35 +0000 |
commit | b43aeadbc9a42c845a50c28ceb1c148e39e77cb9 (patch) | |
tree | e82da0d0dfb3d36e3ae9c5756f03b710bf631437 /src/libstore/references.cc | |
parent | 4cab35d1a691009b43fb0c47574ae0e4baa0b65d (diff) | |
download | guix-b43aeadbc9a42c845a50c28ceb1c148e39e77cb9.tar.gz |
* Don't allocate more than SIZE_MAX bytes.
Diffstat (limited to 'src/libstore/references.cc')
-rw-r--r-- | src/libstore/references.cc | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/libstore/references.cc b/src/libstore/references.cc index aba4ef0107..6f34b14973 100644 --- a/src/libstore/references.cc +++ b/src/libstore/references.cc @@ -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); |