From 64b27c0dd335b9f6343a950c7caf476dcc9bf338 Mon Sep 17 00:00:00 2001 From: Xuan Sang LE Date: Sat, 17 Mar 2018 15:49:37 +0100 Subject: [PATCH] fix invalid read problem --- http_server.c | 6 ++++-- libs/utils.c | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/http_server.c b/http_server.c index e50accd..33dd201 100644 --- a/http_server.c +++ b/http_server.c @@ -881,13 +881,15 @@ dictionary decode_url_request(const char* query) while ((token = strsep(&str_copy, "&"))) { char* key; - char* val; + char* val = NULL; if(strlen(token)>0) { key = strsep(&token,"="); if(key && strlen(key)>0) { - val = strsep(&token,"="); + val = strsep(&token,"="); + if(!val) + val = ""; dput(dic,key,url_decode(val)); } } diff --git a/libs/utils.c b/libs/utils.c index 5a5d967..b54b8c0 100644 --- a/libs/utils.c +++ b/libs/utils.c @@ -249,6 +249,8 @@ int regex_match(const char* expr,const char* search, int msize, regmatch_t* matc return ret; } char *url_decode(const char *str) { + if(!str) + return NULL; char *pstr = str, *buf = malloc(strlen(str) + 1), *pbuf = buf; while (*pstr) {