Closed jkrems closed 1 year ago
Thanks for the PR. Looks like a real issue, an out-of-bounds pointer is being dereferenced.
Your fix works, and will bail out the loop before the dereference happens. The following code might make the intent a bit clearer:
while (base64_stream_decode(&state, &ref[inpos], (inpos + bs > reflen) ? reflen - inpos : bs, &enc[enclen], &partlen)) {
enclen += partlen;
inpos += bs;
// Has the entire buffer been consumed?
if (inpos >= 400) {
break;
}
}
But no need to change it.
As a side note, I'd be interested in running asan
in CI. Did you find this issue with gcc
or clang
's address sanitizer, or were you using another tool?
Updated to use the suggested pattern.
More precisely, this was found via clang
's -fsanitize=bounds
. Needed to look up the exact setup because I was building via bazel. The error will show up in this projects setup with:
make -C test CFLAGS=-fsanitize=bounds
That is, it will print an error though exit code is still 0. I didn't dig more deeply than that. :)
Thanks for the update, I'll merge it shortly. Also thanks for posting the code to reproduce the warning. I've added it to my own build script.
Merged after rebasing.
Sorry for reopening and reclosing, I forgot to annotate the commit with Resolves #105
. Made some stealthy force-pushes to master
to fix. Nothing to see here...
When running the tests with address sanitizer enabled, it fails with the following error:
I think adding this bounds check preserves the semantics of the test but I'm not super familiar with the codebase.