Thu 14 Dec 2006 04:13:54 PM UTC, comment #1:
The problem appears to be that gcc with -O2 is emitting code for its own version of strcasecmp() instead of building what's present in sbr/strcasecmp.c. I ran into the problem on FC5, using GCC 4.1.1 20060525 (Red Hat 4.1.1-1).
The crash occurs when show invokes mhl, which calls strcasecmp().
A simple test program to demonstrate the program (stest.c) is:
#include <stdio.h>
main(int argc, char *argv[])
{
printf("Result: %u\n", strcasecmp(NULL, "test_string");
}
Using GCC 4.x, compilie and link this with strcasecmp.o, like so:
cc -O2 -o stest strcasecmp.o stest.c
and it will dump core when run.
I could be completely wrong here, but I believe that GCC sees the function name "strcasecmp", and says, "Hey! I've got a builtin for this. Here's the code." The code it supplies has no check for NULL, so when NULL is passed in, KA-BOOM!. If strcasecmp.c is built with the -fno-builtin-strcasecmp switch, the correct code (with NULL checks and tolower() calls) is be generated.
In a way, the fix has already been applied to CVS because strcasecmp() was renamed mh_strcasecmp() in March of 2006, which works around the problem. (I suspect that this bug was why the function was renamed.)
So, to solve the problem, take your pick of the following solutions:
1) Get and build the source from CVS
2) If you're building from source, apply the patch found at:
http://lists.gnu.org/archive/html/nmh-commits/2006-03/msg00013.html
3) Change the function name in an scripted fashion:
find . -type f -name \*.[ch] -print |
xargs grep casecmp |
sed -e 's/:.*$//' |
sort -u |
while read f; do
cp $f $f.orig
sed -e 's/strcasecmp/mh_strcasecmp/g' \
-e 's/strncasecmp/mh_strncasecmp/g' $f > $f.new
cp $f.new $f
done
4) Build sbr/strcasecmp.c by itself, specifying the -fno-builtin-strcasecmp flag, and built the rest by itself.
5) Persuade someone that GCC 4.x is pervasive enough in the community to warrant either a patch or release. ;-)
|