Skip to content

Commit

Permalink
Properly initialize and free resources in cgi handling (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmidgley authored and jacksonliam committed May 24, 2019
1 parent ddb69b7 commit c4ee6ae
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mjpg-streamer-experimental/plugins/output_http/httpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,15 +835,23 @@ void execute_cgi(int id, int fd, char *parameter, char *query_string)
if(f == NULL) {
DBG("Unable to execute the requested CGI script\n");
send_error(fd, 403, "CGI script cannot be executed");
free(buffer);
close(lfd);
return;
}

while((i = fread(buffer, 1, sizeof(buffer), f)) > 0) {
if (write(fd, buffer, i) < 0) {
fclose(f);
free(buffer);
close(lfd);
return;
}
}

fclose(f);
free(buffer);
close(lfd);
}


Expand Down Expand Up @@ -1222,6 +1230,7 @@ void *client_thread(void *arg)
req.query_string = malloc(len + 1);
if (req.query_string == NULL)
exit(EXIT_FAILURE);
memset(req.query_string, 0, len + 1);
strncpy(req.query_string, pb, len);
} else {
req.query_string = malloc(2);
Expand Down

0 comments on commit c4ee6ae

Please sign in to comment.