common: fix pointer-before-start UB in drop_incomplete_utf8#916
common: fix pointer-before-start UB in drop_incomplete_utf8#916dxbjavid wants to merge 2 commits into
Conversation
drop_incomplete_utf8() computes strchr(c, 0) - 1, which is undefined
when c is empty. The empty case is reached from
avahi_alternative_service_name(" #N") and avahi_alternative_host_name("-N")
via avahi_strndup(s, 0); fuzz-domain exercises both entry points.
|
As mentioned in another PR one-off fixes with no tests aren't considered especially in cases like this where tests are straightforward. I'll keep it open as a bug report though. Generally it would probably be better to open issues first and mention how issues are discovered along with all the details like the tooling, *san/Valgrind backtraces, the output of static analyzers and their names or anything like that. I'll also point to https://github.com/avahi/avahi/blob/master/.github/CONTRIBUTING.md again
|
|
Fair enough on the test. Pushed one to alternative-test.c that runs the two inputs which reach drop_incomplete_utf8() with an empty string (" #1" and "-2", both via avahi_strndup(s, 0)). On how it turned up: this came from reading the trimming loop rather than a crash. |
The code is already exercised by the fuzz targets so in terms of testing the function the new tests don't add much without assertions making sure that it works as expected. |
drop_incomplete_utf8() computes
strchr(c, 0) - 1, which is undefinedwhen c is empty. The empty case is reached from
avahi_alternative_service_name(" #N") and avahi_alternative_host_name("-N")
via avahi_strndup(s, 0); fuzz-domain exercises both entry points.