Introduce a new add_off_t static function that exits with an error message if there's an overflow, otherwise returns their sum. Use this when adding values obtained from the input patch.
Details
Diff Detail
- Lint
Lint Skipped - Unit
Tests Skipped
Event Timeline
usr.bin/bsdiff/bspatch/bspatch.c | ||
---|---|---|
78 | Is this variant of the code so much better than explicit overflow checks below that it warrants coding the same check twice ? You need to do the explicit check anyway, so why bother ? What can be done, instead, is to add e.g. sys/cdefs.h macro ADD_OF_CHECKED(a,b,result) and make this functionality generally useful, to avoid open-coding the same fragment several times. typeof() macro or generic C11 facility would allow to make that type-neutral. |
usr.bin/bsdiff/bspatch/bspatch.c | ||
---|---|---|
78 | Or may be sys/param.h is better place. |
usr.bin/bsdiff/bspatch/bspatch.c | ||
---|---|---|
78 | We could do away with the bzctrllen > OFF_MAX - HEADER_SIZE, bzctrllen + HEADER_SIZE > OFF_MAX - bzdatalen and bzctrllen + HEADER_SIZE > OFF_MAX - bzdatalen checks if we were so inclined. This approach is harder to get wrong (by missing an explicit overflow check), and is resilient to future changes in variable types. |