about summary refs log tree commit diff
path: root/src/libstore/references.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-09-22T11·13+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-09-22T11·13+0000
commitb43aeadbc9a42c845a50c28ceb1c148e39e77cb9 (patch)
treee82da0d0dfb3d36e3ae9c5756f03b710bf631437 /src/libstore/references.cc
parent4cab35d1a691009b43fb0c47574ae0e4baa0b65d (diff)
* Don't allocate more than SIZE_MAX bytes.
Diffstat (limited to 'src/libstore/references.cc')
-rw-r--r--src/libstore/references.cc7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/libstore/references.cc b/src/libstore/references.cc
index aba4ef01072f..6f34b1497393 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);