fix some unsafe convert

This commit is contained in:
wujiaxu
2020-08-04 12:21:34 +08:00
parent d9dc1c976d
commit ce3b1d2dd7
3 changed files with 11 additions and 10 deletions

View File

@@ -25,6 +25,7 @@
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <atomic>

View File

@@ -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;

View File

@@ -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;