[sprintf] Wrong handling of multiple flags including '0'
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
The bug is in flag parsing in stb_sprintf.h, around lines 490-494, where the '0' flag is handled. Read that block, then compile a small C program that calls the library's sprintf with the four cases in the issue ("%0-10x", "%0+10x", "%0 10x", "%0#10x") and compare against the C standard library output. Done when all four match the standard, with '0' treated as a flag in any position.
Written by the indexing model from the issue text.
Description
The standard says:
After the %, the following appear in sequence:
— Zero or more flags (in any order) that modify the meaning of the conversion specification.
— An optional minimum field width. […]
And:
Note that 0 is taken as a flag, not as the beginning of a field width.
So, the '0' can be in any order relative to the other flags, and it does not mark the end of the flags.
STB vs standard-conforming:
printf("%0-10x", 1); // "-10x" vs "1 "
printf("%0+10x", 1); // "+10x" vs "0000000001"
printf("%0 10x", 1); // " 10x" vs "0000000001"
printf("%0#10x", 1); // "#10x" vs "0x00000001"
Fix: change line 493:
https://github.com/nothings/stb/blob/f0569113c93ad095470c54bf34a17b36646bbbb5/stb_sprintf.h#L490-L494
to:
continue;
- 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