[Toybox] strlower() bug

Ray Gardner raygard at gmail.com
Mon May 6 15:12:54 PDT 2024


While working on an awk implementation for toybox, I found a bug in
strlower(), which is used only in find.c. I've attached some tests to
put in find.test to reveal it. I can't put them here directly because
I don't think the UTF-8 names will come through. (I modelled my awk
tolower()/toupper() code on your strlower().)

The problem is in the test if the output string needs to be enlarged
to take an expanded lowercase:
    // Case conversion can expand utf8 representation, but with extra mlen
    // space above we should basically never need to realloc
    if (mlen+4 > (len = new-try)) continue;

The mlen+4 needs to be mlen-4 to leave at least 4 bytes for the next character.

As the comment indicates, it should "never" need to realloc; it takes
a very long name of uppercase characters that do expand when made
lowercase. But the code is there to handle that very case.

BTW, when I run those tests, they "PASS", but show as aborted:
corrupted size vs. prev_size
scripts/runtest.sh: line 137: 265983 Aborted                 find .
-iname AȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺC
PASS: find utf8 uppercase long name

The test echos and checks the $? return code and the abort apparently
leaves that as 0. Is there a way to fix the test system so it can
force the exit code to be something else? When I run the test from a
command line directly in bash, it gets a code of 134 (SIGABRT).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: findbugtest
Type: application/octet-stream
Size: 2116 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20240506/274badda/attachment.obj>


More information about the Toybox mailing list