Commit ce8657f1 authored by Dmitry Frank's avatar Dmitry Frank Committed by Cesanta Bot

Fix corner case in preparing cgi env

`path_info` was dereferenced without checking for NULL, and a few lines
below, it was checked for NULL.

CL: none

PUBLISHED_FROM=9f14dc68c152b9b1119b276f047686d831bace38
parent 8e366916
...@@ -8845,6 +8845,7 @@ static void mg_prepare_cgi_environment(struct mg_connection *nc, ...@@ -8845,6 +8845,7 @@ static void mg_prepare_cgi_environment(struct mg_connection *nc,
char *p; char *p;
size_t i; size_t i;
char buf[100]; char buf[100];
size_t path_info_len = path_info != NULL ? path_info->len : 0;
blk->len = blk->nvars = 0; blk->len = blk->nvars = 0;
blk->nc = nc; blk->nc = nc;
...@@ -8876,7 +8877,7 @@ static void mg_prepare_cgi_environment(struct mg_connection *nc, ...@@ -8876,7 +8877,7 @@ static void mg_prepare_cgi_environment(struct mg_connection *nc,
mg_conn_addr_to_str(nc, buf, sizeof(buf), MG_SOCK_STRINGIFY_PORT); mg_conn_addr_to_str(nc, buf, sizeof(buf), MG_SOCK_STRINGIFY_PORT);
mg_addenv(blk, "SERVER_PORT=%s", buf); mg_addenv(blk, "SERVER_PORT=%s", buf);
s = hm->uri.p + hm->uri.len - path_info->len - 1; s = hm->uri.p + hm->uri.len - path_info_len - 1;
if (*s == '/') { if (*s == '/') {
const char *base_name = strrchr(prog, DIRSEP); const char *base_name = strrchr(prog, DIRSEP);
mg_addenv(blk, "SCRIPT_NAME=%.*s/%s", (int) (s - hm->uri.p), hm->uri.p, mg_addenv(blk, "SCRIPT_NAME=%.*s/%s", (int) (s - hm->uri.p), hm->uri.p,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment