OT: Crazy C Problem

From: Jeffrey Sharp <jss_at_subatomix.com>
Date: Sun Jan 19 01:15:00 2003

I'm testing the code I've written to spamproof the ClassicCmp web site and
archives. I call the system SpamCamo. The file filter works great and
produces links as it should. The CGI program is not behaving and is giving
me some *very* wierd behavior. I'm stumped.

First, if I compile with this:

    $ cc -o spamcamo.cgi cgi.c spamcamo.cgi.c -lcipher

I get a "Bus error (core dumped)" exception from the first statement in my
program, which is printf("DEBUG: 0\n"). I have used gdb to verify this, and
it tells me that SIGBUS is occuring inside isatty() in libc.

Now, if I compile like this, switching the order of the source files but
making NO changes to the source files themselves:

    $ cc -o spamcamo.cgi spamcamo.cgi.c cgi.c -lcipher

The program proceeds to the first call of strdup(), which returns NULL and
sets errno to EINVAL. strdup() is definitely receiving a valid string.
Furthermore, malloc(1) (as in "allocate one byte") in the same place also
fails with EINVAL. The machine is not low on memory. Even furthermore, the
code that is failing in this case (in cgi.c) works correctly when compiled
against a test program (proof: http://www.subatomix.com/test_cgi.cgi?a=b)
instead of spamcamo.cgi.c. This is what the program does (i.e. not much)
before calling strdup():

    function call
      function call
      funcion call
      strdup() <--- SIGBUS occurs here

I get the same results on two FreeBSD boxen. One is running 4.5-RELEASE and
the other is running 4.6-STABLE. I'd like to think this is something I've
done wrong and not a bug in libc. Any ideas?

Jeffrey Sharp
Received on Sun Jan 19 2003 - 01:15:00 GMT

This archive was generated by hypermail 2.3.0 : Fri Oct 10 2014 - 23:36:02 BST