sqlite: fix undefined behaviour in Session::Changeset()#63637
Conversation
If `nChangeset == 0`, the pointer `pChangeset` may be nullptr. Passing a nullptr to `memcpy()` is undefined behaviour. This can be triggered by running the test suite under UBSAN. Signed-off-by: ndossche <nora.dossche@ugent.be>
|
Review requested:
|
|
If
|
Codecov Reportβ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #63637 +/- ##
==========================================
- Coverage 90.30% 90.29% -0.02%
==========================================
Files 730 730
Lines 234802 234804 +2
Branches 43957 43951 -6
==========================================
- Hits 212041 212017 -24
- Misses 14485 14493 +8
- Partials 8276 8294 +18
π New features to boost your workflow:
|
Well, I tested this without error injection, so perhaps the documentation is wrong. This success return path takes the size and pointer from the |
Renegade334
left a comment
There was a problem hiding this comment.
This success return path takes the size and pointer from the
bufobject, which is initialized to all zero bytes at the start of the function. If the loop does not run then both the pointer and size will be nullptr/0.
This analysis appears correct to me, although libc's are realistically going to handle this gracefully, even if technically UB.
(It's becoming defined behaviour in c2y π)
Right, although the main concern is what a smart compiler may do ;p
Fortunately |
|
OK maybe we should report this upstream, the SQLite folks are amazingly responsive. |
If
nChangeset == 0, the pointerpChangesetmay be nullptr. Passing a nullptr tomemcpy()is undefined behaviour. This can be triggered by running the test suite under UBSAN.Note: this was found by a static-dynamic analyser I'm developing.