From b43aeadbc9a42c845a50c28ceb1c148e39e77cb9 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 22 Sep 2006 11:13:35 +0000 Subject: [PATCH] * Don't allocate more than SIZE_MAX bytes. --- src/libstore/references.cc | 7 +++++++ 1 file changed, 7 insertions(+) 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 #include +#include + 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);