diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2018-09-26T10·03+0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2018-09-26T10·03+0200 |
commit | 44e86304b611a955f4e934fc160f3f4a0a2b1c92 (patch) | |
tree | 4c8388c67886b406bf8b9b07de90b6a3b97167a8 /src/libutil/serialise.cc | |
parent | 7ccdcc7fed154b6621397417354df4e2fd913215 (diff) |
Make NAR header check more robust
Changes std::bad_alloc into bad archive: input doesn't look like a Nix archive
Diffstat (limited to 'src/libutil/serialise.cc')
-rw-r--r-- | src/libutil/serialise.cc | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc index 17448f70efb6..31df6fdfde86 100644 --- a/src/libutil/serialise.cc +++ b/src/libutil/serialise.cc @@ -268,16 +268,17 @@ void readPadding(size_t len, Source & source) size_t readString(unsigned char * buf, size_t max, Source & source) { auto len = readNum<size_t>(source); - if (len > max) throw Error("string is too long"); + if (len > max) throw SerialisationError("string is too long"); source(buf, len); readPadding(len, source); return len; } -string readString(Source & source) +string readString(Source & source, size_t max) { auto len = readNum<size_t>(source); + if (len > max) throw SerialisationError("string is too long"); std::string res(len, 0); source((unsigned char*) res.data(), len); readPadding(len, source); |