c-strip: NULL-pointer dereference (crash) on input that produces no output, e.g. a lone /
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
Research direction
Start in c-strip.c at strip_trailing_space() line 118 and trace the buffer handling from strip_file() line 262, using printf '/' | ./c-strip as the reproducer. Build with AddressSanitizer and UndefinedBehaviorSanitizer, then verify that a lone slash no longer causes a NULL-pointer write or crash.
Written by the indexing model from the issue text.
Description
c-strip crashes with a NULL-pointer write when a processed line produces no output, leaving the output buffer unallocated. The simplest trigger is an input consisting of a single '/'.
Reproduce:
printf '/' | ./c-strip
Built with -fsanitize=address,undefined:
c-strip.c:118:20: runtime error: store to null pointer of type 'char'
AddressSanitizer: SEGV on unknown address 0x000000000000 (WRITE)
#0 strip_trailing_space c-strip.c:118
#1 strip_file c-strip.c:262
Cause:
The output buffer o->p is only allocated on the first addc() call. A lone / sets state = SLASH without emitting output, so addc() is never called and o->p stays NULL. strip_trailing_space() then dereferences it:
buf->p[buf->len] = '\0'; /* c-strip.c:118 — buf->p is NULL, buf->len is 0 */
- Dominant language
- C
- Stars
- 13
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
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.
Similar issues
-
level/task module/gcp type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
docs
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
P3 sonic-vpp
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
sonic-net/sonic-buildimage#29662 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
spack/spack-packages#6586 ·
-
category:port-update
Difficulty 2/5 1-3 hours Newbie friendliness 72/100