fuzz: FuzzedFileProvider::write should not return negative value

Doing so can lead to a glibc crash. Also the manpage for fopencookie
warns against this: https://man7.org/linux/man-pages/man3/fopencookie.3.html
This commit is contained in:
eugene 2022-02-27 17:03:35 -05:00
parent ee8c997125
commit fc471814dc
No known key found for this signature in database
GPG key ID: 118759E83439A9B1

View file

@ -566,7 +566,7 @@ ssize_t FuzzedFileProvider::write(void* cookie, const char* buf, size_t size)
SetFuzzedErrNo(fuzzed_file->m_fuzzed_data_provider);
const ssize_t n = fuzzed_file->m_fuzzed_data_provider.ConsumeIntegralInRange<ssize_t>(0, size);
if (AdditionOverflow(fuzzed_file->m_offset, (int64_t)n)) {
return fuzzed_file->m_fuzzed_data_provider.ConsumeBool() ? 0 : -1;
return 0;
}
fuzzed_file->m_offset += n;
return n;