There was an access past the end of buffer for buffers not terminated by zero.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Did you check if you can reproduce it with a unittest by passing in a Buffer that's not nil-terminated?
clang/lib/Basic/SourceManager.cpp | ||
---|---|---|
1255–1258 | It might be better to check if I is <. than the size of the buffer here and down below to avoid extra pointer arithmetic. |
I tried but couldn't reproduce a segfault. Do you have any suggestion on how to reasonably reliably (TM) reproduce it?
It might be hard to test in a regular build: you probably would need to construct a test-case where the buffer is precisely a multiple of the page size and not nil-terminated, and then hopefully the OS will trigger a fault once you access the out of bounds character. Have you tried ASANified build? I think it could trigger a crash even if you don't get the pages right and just have a not-nil terminated buffer.
LGTM, with a nit mentioned.
clang/unittests/Basic/SourceManagerTest.cpp | ||
---|---|---|
249 | Nit: you can use std::unique_ptr<char[]> to avoid the manual delete[] below. |
It might be better to check if I is <. than the size of the buffer here and down below to avoid extra pointer arithmetic.