<div dir="ltr">Hi,<br><br>I am writing to report a bug in the strrchr function of klibc.<br>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 <a href="https://mirrors.edge.kernel.org/pub/linux/libs/klibc/2.0/klibc-2.0.11.tar.gz" target="_blank">Linux Kernel Archives</a>.<br>Please find a detailed report below.<br><br>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'.<br>An example input is:<br>    const char src[] = {128, '\0'};<br>    char *ret = strrchr(src, 0);<br>    if (!ret) {<br>        printf("BUG!\n");<br>    }<br><br>The file that demonstrates the bug can be found <a href="https://github.com/compilerai/bug-reports/blob/master/bug_files/klibc_strrchr_bug.c" target="_blank">here</a>.<br><br>0: <a href="https://man7.org/linux/man-pages/man3/strchr.3.html" target="_blank">https://man7.org/linux/man-pages/man3/strchr.3.html</a><br><br>Thanks,<br><br>Jai Arora, Abhishek Rose, Shubhani Gupta, Sorav Bansal<br>CompilerAI Research Group<br>IIT Delhi, India<br></div>