Repository navigation
Commit 9d2720a
authored
Fix #15180 internalError in checkFormatString on invalid width or position (#8982)
CheckIOImpl::checkFormatString converts the digits collected for a field
width or a POSIX parameter position with strToInt<int>, which throws
when the digits are empty (`%$d`), start with a zero (`%01$d`, which
glibc accepts) or do not fit in an int (`%99999999999$d`,
`scanf("%99999999999s", buf)` with a known array), so one such format
string makes CppCheck::checkFile bail out with an internalError and drop
every other diagnostic for that file. Replaced the conversion with a
small helper that parses the digits without throwing and clamps anything
above INT_MAX, and a `$` with no digits in front is no longer taken as a
parameter position; widths and positions that fit in an int behave
exactly as before, while an oversized one is now reported through the
existing invalidScanfFormatWidth and
wrongPrintfScanfParameterPositionError messages, with 2147483647 shown
for the clamped value. Verified with an ASan/UBSan build: the new
asserts in TestIO::testScanf4 and testPosixPrintfScanfParameterPosition
throw on main and pass with the fix, the full testrunner is green, and
the selfcheck options report nothing for lib/checkio.cpp. I do not have
Trac access, so could you create a ticket for this? I will update the
title to reference it once there is a number.1 parent 68bf94a commit 9d2720a
2 files changed
Lines changed: 37 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
794 | 795 | | |
795 | 796 | | |
796 | 797 | | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
797 | 812 | | |
798 | 813 | | |
799 | 814 | | |
| |||
853 | 868 | | |
854 | 869 | | |
855 | 870 | | |
856 | | - | |
857 | | - | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
858 | 875 | | |
859 | 876 | | |
860 | 877 | | |
| |||
906 | 923 | | |
907 | 924 | | |
908 | 925 | | |
909 | | - | |
| 926 | + | |
910 | 927 | | |
911 | 928 | | |
912 | 929 | | |
| |||
929 | 946 | | |
930 | 947 | | |
931 | 948 | | |
932 | | - | |
| 949 | + | |
933 | 950 | | |
934 | 951 | | |
935 | 952 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
899 | 899 | | |
900 | 900 | | |
901 | 901 | | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
902 | 910 | | |
903 | 911 | | |
904 | 912 | | |
| |||
4274 | 4282 | | |
4275 | 4283 | | |
4276 | 4284 | | |
| 4285 | + | |
| 4286 | + | |
| 4287 | + | |
| 4288 | + | |
| 4289 | + | |
| 4290 | + | |
| 4291 | + | |
| 4292 | + | |
4277 | 4293 | | |
4278 | 4294 | | |
4279 | 4295 | | |
| |||
0 commit comments