Reputation: 1131
I have a generic file fetcher C program that works flawlessly when run on the shell, but after converting to a CGI script and running same program, crashes at the point
curl = curl_easy_init();
I say again, this works well in shell mode and I get the file I want, but in CGI it just crashes the script.
EDIT: Here's Apache log after script breaks.
malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
Okay, so these are the initializations I am making to read POST data from a form.
len = atoi((char *) getenv("CONTENT_LENGTH"));
posted = malloc(len + 1);
decoded = malloc(len + 100); // Currently for pics only 10 * 10 pics
//fgets(data, length, stdin);
fread(posted, len, 1, stdin); // rawdata contains standard input coming from HTTP POST
printf("POST: %s\n", posted);
decode_post_keys_(posted, decoded, len+100); // Decode POST values
printf("DECODED: %s\n", decoded);
decode_value("id=", value, MAX_LEN);
The program quits when I am reading the a selection, this is a YouTube URL through which I run a program that fetches the mp4 file.
printf("Video url: %s\n", row[0]);
/** Get the video ID from the string "v=" */
decode_value_post("v=", value, "http://www.youtube.com/watch?v=acq8BvIhUTg", /*row[0],*/ MAX_URL);
//strcpy(value, "acq8BvIhUTg");
printf("YouTube video id: %s\n", value);
muxer.youtube_url[0] = '\0';
strcpy(muxer.youtube_url, "http://www.youtube.com/get_video_info?video_id =");
strcat(muxer.youtube_url, value);
muxer.youtube_url[strlen(muxer.youtube_url)+1] = '\0';
muxer.vid_filesize = get_youtube_file(muxer.youtube_url, &muxer); // This is where it fails
printf("FILE-SIZE: %d\n", muxer.vid_filesize);
So, the function get_youtube_file has the curl_easy_init() which fails.
Upvotes: 1
Views: 275
Reputation: 1131
Okay found the solution. I haven't posted another function that actually decodes the posted data. And apparently the variable doesn't have enough room to hold the decoded data. I have improved it to 5000 extra, and it works.
size_t len = atol((char *) getenv("CONTENT_LENGTH"); // post data length
char *decoded = malloc(len + EXTRA);
decode_post_keys_(posted, decoded, len+EXTRA);
This worked. :-)
Upvotes: 1