X-Git-Url: https://the.earth.li/gitweb/?a=blobdiff_plain;f=getcgi.c;h=7c0656020690be5e14dddb57fcf5fb8a98f59f52;hb=e83421524e00d9cd636ad697eb3121f504339c9e;hp=b36ad9b3e2f2d39688c18c06079ecab19f9e1ad7;hpb=83ae316a7b14e55418349e87d1a1942a0627ae14;p=onak.git diff --git a/getcgi.c b/getcgi.c index b36ad9b..7c06560 100644 --- a/getcgi.c +++ b/getcgi.c @@ -16,8 +16,7 @@ * more details. * * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * this program. If not, see . */ #include @@ -140,7 +139,7 @@ void unescape_url(char *url) char **getcgivars(int argc, char *argv[]) { int i; - char *request_method; + char *request_method, *env; int content_length, paircount; char *cgiinput = NULL; char **cgivars = NULL; @@ -162,27 +161,31 @@ char **getcgivars(int argc, char *argv[]) return NULL; } else if (!strcmp(request_method, "GET") || !strcmp(request_method, "HEAD")) { - cgiinput=strdup(getenv("QUERY_STRING")); + env = getenv("QUERY_STRING"); + if (env != NULL) { + cgiinput = strdup(env); + } } else if (!strcmp(request_method, "POST")) { - if (getenv("CONTENT_TYPE") != NULL && - strcasecmp(getenv("CONTENT_TYPE"), - "application/x-www-form-urlencoded")) { + env = getenv("CONTENT_TYPE"); + if ((env != NULL) && strcasecmp(env, + "application/x-www-form-urlencoded")) { printf("getcgivars(): Unsupported Content-Type.\n"); exit(1); } - - if (!(content_length = atoi(getenv("CONTENT_LENGTH")))) { + + env = getenv("CONTENT_LENGTH"); + if ((env == NULL) || !(content_length = atoi(env))) { printf("getcgivars(): No Content-Length was sent with" " the POST request.\n"); exit(1); } - - if (!(cgiinput= (char *) malloc(content_length+1))) { + + if (!(cgiinput = (char *) malloc(content_length+1))) { printf("getcgivars(): Could not malloc for " "cgiinput.\n"); exit(1); } - + if (!fread(cgiinput, content_length, 1, stdin)) { printf("Couldn't read CGI input from STDIN.\n"); exit(1); @@ -195,6 +198,11 @@ char **getcgivars(int argc, char *argv[]) exit(1); } + /* If we didn't get any cgiinput info, nothing to return */ + if (cgiinput == NULL) { + return NULL; + } + /* Change all plusses back to spaces */ for(i=0; cgiinput[i]; i++) if (cgiinput[i]=='+') cgiinput[i] = ' ';