Update a couple of functions to know buffer length - #21
Conversation
Closed PR commentsThis overlaps #26 but is not subsumed by it, so flagging the interaction rather than claiming otherwise. #26 rewrites the same code in What #26 does not take from this PR is the If you want to take it further, the version I would suggest is the check in the shipped binary rather than an assert, returning an error the way the surrounding failure paths do. Both prototypes live in uninstalled headers, so the signature change is free. Rebasing this over #26 should be mechanical — the lines it touches are adjacent to, not the same as, the ones #26 changes. |
aa3dde7 to
075d237
Compare
075d237 to
443a28b
Compare
443a28b to
48f9a7e
Compare
|
Rebased onto current Rebase
Commit messageSubject given the project's No regression test — and whyThe change is a signature change plus What is worth recording is that the new bound is live-exercised rather than dead: Build and testmacOS/arm64, Ninja,
|
48f9a7e to
c8906a0
Compare
modify_all_fields() and modify_field() wrote into a caller-supplied buffer at an offset taken from the field table, with no way to check that the write stayed inside it. Both now take the buffer size, and modify_field() rejects a field whose offset plus size * len exceeds it. The check sits ahead of the switch, so it covers every write path rather than the string case alone, and it reports and returns like the other failures in the function; an assert() would compile away in the release builds that ship. No field table can trip it today: check_total_size() already requires the offsets to tile the structure exactly. It bounds future edits to them.
c8906a0 to
41fa064
Compare
|
Rebased onto current The bounds check did not exist in any shipping build. What the 2 warnings actually wereReproduced locally with the Exactly the 2 the dashboard counted, in both tool files. The check is now real, and covers every write path
The check now sits ahead of the /* every case below writes field->len elements at field->offset */
if( field->offset < 0 || field->size < 0 || field->len < 0 ||
(size_t)field->offset + (size_t)field->size * (size_t)field->len > baselen )
{
fprintf(stderr,"** field '%s' (offset %d, %d x %d bytes) does not fit "
"in a %zu byte structure\n",
field->name, field->offset, field->len, field->size, baselen);
return 1;
}It reports and returns 1 like every other failure in the function rather than Note the arithmetic differs from the assert's: the assert compared No red-green test, and why none is possibleThe condition is unreachable from user input. So this is hardening against a future edit to those tables, not a fix for a Verification
The 370 include the |
7356eb1
into
InsightSoftwareConsortium:master
|
Great, thanks for reviewing this one! I should get back to my fbound-safety work... it was getting pretty close... |
|
Wait a sec, you changed my code. Please don't change my code, give me no time to review your changes, then merge it under my name. I am listed as commit author and I do not approve/like the changes you made. This PR had been open for 9 months, you don't look at it in all that time (that's fine!), then you modify my work and merge it all within 17 hours (that's not fine!). |
Without the buffer length, the function can't really be implemented safely. For now, only use the new length parameter in an assert.