Undefined behavior in ResultAdd()
Closed / Fixedbca10e3790f6c2962c0302d6f62ef9c6fadf5752Created 5 years agoUpdated 5 years ago
Descriptionwiki2021-12-28 23:11:04
ResultAdd() (generic/tclIOGT.c) is sometimes called with size_t toWrite = 0 and a ResultBuffer *r such that r->buf = NULL. In this case, r->used = 0 and r->allocated = 0, so ResultAdd() will not allocate a new buffer. This leads to NULL + 0 pointer arithmetic when doing r->buf + r->used, and calling memcpy() with NULL as the destination (even though the copy length toWrite is 0), both of which are undefined behavior. UBSan -fsanitize=nonnull-attribute (GCC) and -fsanitize=pointer-overflow errors during test iogt-1.1:
tcl/generic/tclIOGT.c:1445:5: runtime error: null pointer passed as argument 1, which is declared to never be null
tcl/generic/tclIOGT.c:1445:12: runtime error: applying zero offset to null pointer
Referenced by2
58281c1992Fix [bca10e3790]: Undefined behavior in ResultAdd(). Make functions like ResultAdd() equal in tclIOGt.c and tclIOTrans.c check-in2022-01-14 09:53:14acb2cec2bdSuggested fix for [bca10e3790]: Undefined behavior in ResultAdd(). Make functions like ResultAdd() equal in tclIOGt.c and tclIOTrans.c check-in2022-01-13 11:12:40
jan.nijtmanswiki2022-01-13 11:41:58
Suggested fix [here]. This also makes various functions in tclIOGT.c and tclIOTrans.c equal (since the ResultAdd() function in tclIOTrans.c didn't have this problem)
jan.nijtmans Closed ticket [bca10e3790].
[History diff]2022-01-14 22:49:53
Log in (anonymous is fine) to add a comment.