From eef7760870d99beca75cf96262f4721563198a42 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Mon, 27 Apr 2020 08:17:51 +0200 Subject: [PATCH] datasets: reputation value validation --- src/datasets.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/datasets.c b/src/datasets.c index 68557f3a42..46f39d1926 100644 --- a/src/datasets.c +++ b/src/datasets.c @@ -32,6 +32,7 @@ #include "util-print.h" #include "util-crypt.h" // encode base64 #include "util-base64.h" // decode base64 +#include "util-byte.h" SCMutex sets_lock = SCMUTEX_INITIALIZER; static Dataset *sets = NULL; @@ -138,12 +139,14 @@ static int ParseRepLine(const char *in, size_t ins, DataRepType *rep_out) return -1; } - int v = atoi(ptrs[0]); - if (v < 0 || v > USHRT_MAX) { - SCLogDebug("v %d", v); + uint16_t v = 0; + int r = StringParseU16RangeCheck(&v, 10, strlen(ptrs[0]), ptrs[0], 0, USHRT_MAX); + if (r != (int)strlen(ptrs[0])) { + SCLogError(SC_ERR_INVALID_NUMERIC_VALUE, + "'%s' is not a valid reputation value (0-65535)", ptrs[0]); return -1; } - SCLogDebug("v %d raw %s", v, ptrs[0]); + SCLogDebug("v %"PRIu16" raw %s", v, ptrs[0]); rep_out->value = v; return 0;