[klibc] Bug in strrchr

Bugs Reporter bugs at compiler.ai
Wed Dec 28 03:31:56 PST 2022


I am writing to report a bug in the strrchr function of klibc.
The bug is in the C implementation of strrchr as located in the usr/klibc/
directory of the klibc repository. The klibc version was `2.0.11` and the
source code was downloaded from the Linux Kernel Archives
Please find a detailed report below.

Linux[0] manpage for strrchr() specifies that the terminating null byte is
considered part of the string, so that if c is specified as '\0', this
function returns a pointer to the terminator. klibc's implementation does
not follow this and thus gives wrong output when `c' is '\0'.
An example input is:
    const char src[] = {128, '\0'};
    char *ret = strrchr(src, 0);
    if (!ret) {

The file that demonstrates the bug can be found here

0: https://man7.org/linux/man-pages/man3/strchr.3.html


Jai Arora, Abhishek Rose, Shubhani Gupta, Sorav Bansal
CompilerAI Research Group
IIT Delhi, India
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zytor.com/archives/klibc/attachments/20221228/54473825/attachment.htm>

More information about the klibc mailing list