diff options
author | Tor Brede Vekterli <vekterli@yahooinc.com> | 2022-05-05 10:54:35 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@yahooinc.com> | 2022-05-05 10:58:56 +0000 |
commit | 9672b125531f4d3eda3d8483cf1d63d71ebc9875 (patch) | |
tree | 245b4c753370d661e7a504146221c5dd4af85934 /vespalib | |
parent | a6f4bcefc08cb924b179cc1eadd9b2f95f2ffab1 (diff) |
Early return from asciistream file read if file is empty
Avoids a transitive vespalib::string append with nullptr buffer and
zero length, which in turn ends up passing nullptr to memmove, which
is undefined.
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/stllike/asciistream.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/vespalib/src/vespa/vespalib/stllike/asciistream.cpp b/vespalib/src/vespa/vespalib/stllike/asciistream.cpp index eb127c7051a..6b673363d2d 100644 --- a/vespalib/src/vespa/vespalib/stllike/asciistream.cpp +++ b/vespalib/src/vespa/vespalib/stllike/asciistream.cpp @@ -628,6 +628,9 @@ asciistream::createFromFile(stringref fileName) if (sz < 0) { throw IoException("Failed getting size of file " + fileName + " : Error=" + file.getLastErrorString(), IoException::UNSPECIFIED, VESPA_STRLOC); } + if (sz == 0) { + return is; + } alloc::Alloc buf = alloc::Alloc::alloc(sz); ssize_t actual = file.Read(buf.get(), sz); if (actual != sz) { |