stb_sprintf: potential out-of-bound read from static analysis
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
Research direction
The question lives in stb_sprintf.h around the indexing into the stbsp__powten table, near the branch that computes e from frac_digits and dg. Read that block to confirm the bounds the reporter describes, then decide between the two proposed fixes: a guard on e or enlarging the stbsp__powten array. Done when the index is provably within the table, or the table is sized to cover it, and the analyzer warning no longer applies.
Written by the indexing model from the issue text.
Description
while running a static analyzer for an application, I stumbled upon this code in stb_sprintf.
Since line 1782 is reached when the if at 1780 is false, the tool assume e can get up to 23, so it would read out of bounds of the stbsp__powten[20] array.
now if one reads the rest of the code it's apparent that that's not possible: frac_digits is at most 23 entering the first if, dg can be anything between 10 and 20 so e will be in the range 3-13.
Anyway, I think it would be a good defensive measure to either replace line 180 with:
if ((stbsp__uint32)e >= 20)
or define a stbsp__powten[23]
- Dominant language
- C
- Stars
- 18
- Forks
- 5
- Avg merge
- 1m
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nothings/stb_sprintf
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
nothings/stb_sprintf#10 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
nothings/stb_sprintf#8 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
nothings/stb_sprintf#5 ·
-
[SECURITY] stbsp_snprintf with count=0 writes null terminator before bufferPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
nothings/stb_sprintf#4 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
nothings/stb_sprintf#20 ·
All issues in nothings/stb_sprintf
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 5 days
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
bug severity: medium
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
AlessandroSangiuliano/Uros#1014 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
OpenXiangShan/NEMU#1314 ·
Maintainers usually reply within 1 day