Fix some issues reported by Coverity

This commit is contained in:
Mike Gelfand 2017-05-16 21:37:00 +03:00
parent 1e3d20422a
commit 6b0229a546
4 changed files with 11 additions and 5 deletions

View File

@ -228,7 +228,7 @@ void tr_logAddMessage(char const* file, int line, tr_log_level level, char const
if (buf_len < 0)
{
return;
goto finish;
}
#ifdef _WIN32
@ -302,6 +302,7 @@ void tr_logAddMessage(char const* file, int line, tr_log_level level, char const
}
}
finish:
tr_lockUnlock(getMessageLock());
errno = err;
}

View File

@ -856,6 +856,7 @@ void tr_rpcSetWhitelist(tr_rpc_server* server, char const* whitelistStr)
char const* delimiters = " ,;";
size_t const len = strcspn(walk, delimiters);
char* token = tr_strndup(walk, len);
tr_list_append(&server->whitelist, token);
if (strcspn(token, "+-") < len)
@ -868,12 +869,14 @@ void tr_rpcSetWhitelist(tr_rpc_server* server, char const* whitelistStr)
tr_logAddNamedInfo(MY_NAME, "Adding address to whitelist: %s", token);
}
if (walk[len] == '\0')
walk += len;
if (*walk == '\0')
{
break;
}
walk += len + 1;
++walk;
}
}

View File

@ -23,6 +23,8 @@
#include "variant.h"
#include "variant-common.h"
#define MAX_BENC_STR_LENGTH (128 * 1024 * 1024) /* arbitrary */
/***
**** tr_variantParse()
**** tr_variantLoad()
@ -115,7 +117,7 @@ int tr_bencParseStr(uint8_t const* buf, uint8_t const* bufend, uint8_t const** s
errno = 0;
len = strtoul((char const*)buf, &ulend, 10);
if (errno != 0 || ulend != end)
if (errno != 0 || ulend != end || len > MAX_BENC_STR_LENGTH)
{
goto err;
}

View File

@ -121,7 +121,7 @@ void Session::portTest()
if (r.success)
{
tr_variantDictFindBool(r.args.get(), TR_KEY_port_is_open, &isOpen);
(void)tr_variantDictFindBool(r.args.get(), TR_KEY_port_is_open, &isOpen);
}
emit portTested(isOpen);