https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93641
Bug ID: 93641 Summary: Wrong strncmp and strncasecmp size arguments Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: dominik.b.czarnota+bugzilla at gmail dot com Target Milestone: --- Hello, There are several bugs where `strcnmp` function is used with a string literal and size that doesn't match the string literal length without a null byte. All of this was found on the following commit: * 8e0efc103 - (grafted, HEAD -> master, origin/master, origin/HEAD) i386: Do GNU2 TLS address computation in ptr_mode (3 weeks ago) <H.J. Lu> I haven't triaged all those cases and I also reported two of them separately in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93640. Below are those cases in the following format: ./gcc/config/i386/i386.c: || strncmp(name, ".lbss.", 5) == 0 strlen=6, n=5 ^-- either one of the strncmp used there is redundant or the 5 should be changed to 6 here ./gcc/config/i386/i386.c: || strncmp(name, ".gnu.linkonce.lb.", 16) == 0) strlen=17, n=16 ^-- it is in the same function as previous case: probably the 16 should be changed to 17 ./gcc/config/darwin-c.c: && !strncmp(identifier_pointer (tn), "CFStringRef", 8)); strlen=11, n=8 ^-- e.g. a CFStringXYZ would be matched here. ./gcc/cp/error.c: if (!strncmp(str, "_zgr", 3)) strlen=4, n=3 ^-- should rather be 4 ./gcc/doc/invoke.texi: strncat(buf, ".txt", 3); strlen=4, n=3 ^-- should rather be 4, though its in .texi files which I don't know what are they for. ./gcc/c-family/c-format.c: && !strncasecmp(format_chars - 3, "can%'t", 5) strlen=6, n=5 ^-- should rather be 6