Repository navigation
[#1727] Reject integers outside int range in as_int - #1728
Keshavkumar04 wants to merge 1 commit into
Conversation
|
static-analysis fails on main too. I built cppcheck 2.22.0 as CI does and ran the baseline check against a clean main checkout: nullPointerOutOfMemory:src/libpgmoneta/art.c: 17 in the baseline, 18 now This branch's output is identical to main's, and configuration.c has no findings. The baseline was last regenerated for 2.19 while CI now builds 2.22.0, which reports one more in art.c. They look like genuine unchecked mallocs (pgmoneta_art_create, pgmoneta_art_iterator_create and a few others), same class as #1590. Is art.c already covered by that work, or would a PR help? |
|
@Keshavkumar04 use MCTF_ASSERT_INT_EQ(config->metrics, 0, ...) instead of >= 0 in test, so we check that the default is kept. Otherwise it looks good. |
cc56da6 to
9d2eaa5
Compare
Done. Unrelated: |
Pranav-error
left a comment
There was a problem hiding this comment.
Looks good to me. I ran the new test on top of this PR's parent: it fails at test_configuration.c:1337 (the -2147483649 value comes back as a positive level), and passes with the change.
The same narrowing is in the sibling projects, which have their own copy of this function: pgagroal_as_int() in pgagroal's src/libpgagroal/configuration.c and as_int() in pgexporter's src/libpgexporter/configuration.c both check only ERANGE and then cast with (int)val. I'll open issues there so it gets cross-ported.
Thanks for checking the siblings. I've got both ports ready, pgexporter's |
|
@Keshavkumar04 Please, rebase |
The ERANGE check covers long, so a value between INT_MAX and LONG_MAX was accepted and then narrowed: 2147483648 became -2147483648 and -2147483649 became INT_MAX, defeating the callers that validate with a negative check. Signed-off-by: Keshav Kumar <[email protected]>
9d2eaa5 to
e954ba0
Compare
Rebased. |
as_intchecksERANGE, which only covers long range, then narrows tointunchecked, so values between INT_MAX and LONG_MAX are accepted and truncated.-2147483649arrives as2147483647, which defeats callers that validate with a negative check, includingas_retention_value.as_bytesandas_secondsboth bound against INT_MAX; this adds the same check toas_int.The new test fails on unfixed code and passes with the fix.
Closes #1727