On my Mac, I have coded up a C cgi program. It works fine in Xcode, and from the Terminal, and when accessed by a html form under Safari and FireFox on the Mac. However, when I access the form on my home network, from my Windows XP machine running IE 6, it crashes when I click "submit" on my form.
Now, here's the tricky part: when it crashes, and IE displays the "Internal Server Error" page, if I click IE's REFRESH button, and click the RETRY popup to confirm resending the form data, the cgi program runs perfect and I get the output! This is blowing my mind!!
Here's the crash log:
Code:
**********
Host Name: todd-burchs-computer
Date/Time: 2008-03-16 08:12:04.574 -0500
OS Version: 10.4.11 (Build 8S2167)
Report Version: 4
Command: getmethod
Path: /Library/WebServer/CGI-Executables/getmethod
Parent: httpd [457]
Version: ??? (???)
PID: 3779
Thread: 0
Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_INVALID_ADDRESS (0x0001) at 0x7da5c33c
Thread 0 Crashed:
0 getmethod 0x00008bba main + 688 (main.c:58)
1 getmethod 0x00001e9a start + 258
2 getmethod 0x00001dc1 start + 41
Thread 0 crashed with X86 Thread State (32-bit):
eax: 0x6f697462 ebx: 0x00008921 ecx: 0x00000000 edx: 0x00000000
edi: 0xbffff229 esi: 0x00008c91 ebp: 0xbffff358 esp: 0xbffff180
ss: 0x0000001f efl: 0x00010202 eip: 0x00008bba cs: 0x00000017
ds: 0x0000001f es: 0x0000001f fs: 0x00000000 gs: 0x00000037
Binary Images Description:
0x1000 - 0x4fff getmethod /Library/WebServer/CGI-Executables/getmethod
0x8000 - 0x8fff getmethod /Library/WebServer/CGI-Executables/getmethod
0x8fe00000 - 0x8fe4afff dyld 46.16 /usr/lib/dyld
0x90000000 - 0x90171fff libSystem.B.dylib /usr/lib/libSystem.B.dylib
0x901c1000 - 0x901c3fff libmathCommon.A.dylib /usr/lib/system/libmathCommon.A.dylib
0x90bd2000 - 0x90bd9fff libgcc_s.1.dylib /usr/lib/libgcc_s.1.dylib
0x963fa000 - 0x963fbfff com.apple.zerolink 1.2 (3) /System/Library/PrivateFrameworks/ZeroLink.framework/Versions/A/ZeroLink
And here's the C program. I'm assuming line 58 is the line where's crashing, so I've highlighted line 58 in red.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//int main (int argc, const char * argv[]) {
int main (int argc, char * const argv[], char * envp[] ) {
int i ;
char * position , * envptr ;
char buffer[256] ;
char * ctype ;
int clength = 0 ;
char const * names[] = {
"CONTENT_LENGTH" ,
"CONTENT_TYPE" ,
"DOCUMENT_ROOT" ,
"HTTP_ACCEPT" ,
"HTTP_ACCEPT_ENCODING" ,
"HTTP_ACCEPT_LANGUAGE" ,
"HTTP_CONNECTION" ,
"HTTP_HOST" ,
"HTTP_REFERER" ,
"HTTP_USER_AGENT" ,
"PATH" ,
"REMOTE_ADDR" ,
"REMOTE_PORT" ,
"SCRIPT_FILENAME" ,
"SCRIPT_URI" ,
"SCRIPT_URL",
"SERVER_ADDR" ,
"SERVER_ADMIN" ,
"SERVER_NAME" ,
"SERVER_PORT" ,
"SERVER_SIGNATURE" ,
"SERVER_SOFTWARE" ,
"GATEWAY_INTERFACE" ,
"SERVER_PROTOCOL" ,
"REQUEST_METHOD" ,
"QUERY_STRING" ,
"REQUEST_URI" ,
"SCRIPT_NAME" ,
NULL
} ;
printf("Content-Type: text/html\n\n") ;
printf("<html>\n") ;
printf("<head><title>From A C Program</title>\n") ;
printf("<style type='text/css'>\n") ;
printf(".yellow { background-color: yellow ; border: 1px solid black ;}\n") ;
printf("</style>\n") ;
printf("</head>\n") ;
printf("<body><p>Hi there</p>\n") ;
printf("<table class='yellow'>\n") ;
i = 0 ;
while( names[i] != NULL ) { // this is line 58
printf("<tr><td>\n") ;
printf("\t%-30s\n", names[i] ) ;
printf("</td><td>\n") ;
strcpy(buffer,names[i]) ;
strcat(buffer,"=") ;
envptr = getenv(names[i]) ;
if (envptr) strcat(buffer, envptr) ;
else strcat(buffer, "(null)") ;
position = strchr(buffer, '=') ;
buffer[position-buffer] = 0 ; // null term the environment variable name
printf("\t%s\n", position+1) ;
if (strcmp("CONTENT_TYPE",buffer)==0) {
ctype = position+1 ;
}
if (strcmp("CONTENT_LENGTH",buffer)==0) {
clength = atoi(position+1) ;
}
printf("</td></tr>\n") ;
i++ ;
}
printf("</table>\n");
printf("<table frame='box' rules='all' cellpadding='5' >\n<tr><td>data... bytes = %d</td>\n<td>", clength );
for ( i = 0 ; i < clength ; ++i ) {
char c = fgetc(stdin) ;
if (c=='\n') printf("<br />") ;
else printf( "%c", c ) ;
}
printf("</td>\n</tr>\n") ;
printf("</table>\n</body>\n");
printf("</html>\n");
fflush(stdout) ;
return 0;
}
Any ideas? If you want me to post the html form, I can do that.
Thanks, Todd