From ce3b1d2dd7ca4c00c4c2f3878f2f3f8a486ee358 Mon Sep 17 00:00:00 2001 From: wujiaxu Date: Tue, 4 Aug 2020 12:21:34 +0800 Subject: [PATCH] fix some unsafe convert --- src/manager/WFGlobal.cc | 1 + src/protocol/redis_parser.c | 2 +- src/util/URIParser.cc | 18 +++++++++--------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/manager/WFGlobal.cc b/src/manager/WFGlobal.cc index 7072ed31..5acf7fb7 100644 --- a/src/manager/WFGlobal.cc +++ b/src/manager/WFGlobal.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include diff --git a/src/protocol/redis_parser.c b/src/protocol/redis_parser.c index f75bf610..f48e9a86 100644 --- a/src/protocol/redis_parser.c +++ b/src/protocol/redis_parser.c @@ -143,7 +143,7 @@ static int __redis_parse_line(redis_parser_t *parser) { char *buf = (char *)parser->msgbuf; char *str = buf + parser->msgidx; - int slen = parser->findidx - parser->msgidx; + size_t slen = parser->findidx - parser->msgidx; char data[32]; int i, n; const char *offset = (const char *)parser->msgidx; diff --git a/src/util/URIParser.cc b/src/util/URIParser.cc index 28bd6ad7..f490746b 100644 --- a/src/util/URIParser.cc +++ b/src/util/URIParser.cc @@ -526,10 +526,10 @@ int URIParser::parse(const char *str, ParsedURI& uri) for (int i = 0; i < 7; i++) { - int len = ed[i] - st[i]; - - if (len > 0) + if (ed[i] > st[i]) { + size_t len = ed[i] - st[i]; + *dst[i] = (char *)realloc(*dst[i], len + 1); if (*dst[i] == NULL) { @@ -540,18 +540,18 @@ int URIParser::parse(const char *str, ParsedURI& uri) memcpy(*dst[i], str + st[i], len); (*dst[i])[len] = '\0'; + + if (i == 2 && len >= 3 && (*dst[2])[0] == '%' && (*dst[2])[1] == '2' && ((*dst[2])[2] == 'F' || (*dst[2])[2] == 'f')) + { + len = StringUtil::url_decode(*dst[2], len); + (*dst[i])[len] = '\0'; + } } else { free(*dst[i]); *dst[i] = NULL; } - - if (i == 2 && len >= 3 && (*dst[2])[0] == '%' && (*dst[2])[1] == '2' && ((*dst[2])[2] == 'F' || (*dst[2])[2] == 'f')) - { - len = StringUtil::url_decode(*dst[2], len); - (*dst[i])[len] = '\0'; - } } uri.state = URI_STATE_SUCCESS;