Skip to content

Fix incorrect usage of strchr leading to overflow.#584

Open
elttil wants to merge 3 commits intolandley:masterfrom
elttil:heapfix
Open

Fix incorrect usage of strchr leading to overflow.#584
elttil wants to merge 3 commits intolandley:masterfrom
elttil:heapfix

Conversation

@elttil
Copy link

@elttil elttil commented Nov 10, 2025

These commits fix issues #574, #578, #579. They all result from using strchr with the incorrect assumption that strchr("foo", '\0') results in NULL, when in actuality they return a pointer to the null terminator in the string "foo". The function stridx in lib/lib.c has taken this issue into account, so I replace the current checks with stridx(<args>) != -1 as it acts in a manner that I assume the original author(s) intended it to.

The strchr check will always succeed when c == '\0' as C strings always
have a null terminator. This fixes the overflow in issue landley#579 which
occurs when sed is given the expression '/[['.
Overflow would occur the command `find - time` was run. This commit
fixes issue landley#578.
When printf is given the format '%*' it would overflow and print
environment variables. This fixes issue landley#574.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant