#include "util-pool.h"
#include "util-radix-tree.h"
#include "util-file.h"
+#include "util-byte.h"
#include "stream-tcp-private.h"
#include "stream-tcp-reassemble.h"
cfg_prec->randomize = ConfValIsTrue(p->val);
}
} else if (strcasecmp("randomize-inspection-range", p->name) == 0) {
- uint32_t range = atoi(p->val);
- if (range > 100) {
- SCLogError(SC_ERR_SIZE_PARSE, "Invalid value for randomize"
- " inspection range setting from conf file - %s."
- " It should be inferior to 100."
+ uint32_t range;
+ if (StringParseU32RangeCheck(&range, 10, 0,
+ (const char *)p->val, 0, 100) < 0) {
+ SCLogError(SC_ERR_INVALID_VALUE, "Invalid value for randomize"
+ "-inspection-range setting from conf file - \"%s\"."
+ " It should be a valid integer less than or equal to 100."
" Killing engine",
p->val);
exit(EXIT_FAILURE);
#include "util-time.h"
#include "util-unittest.h"
#include "util-debug.h"
+#include "util-byte.h"
#include "util-privs.h"
#include "util-signal.h"
#include "unix-manager.h"
const char *interval = ConfNodeLookupChildValue(stats, "interval");
if (interval != NULL)
- stats_tts = (uint32_t) atoi(interval);
+ if (StringParseUint32(&stats_tts, 10, 0, interval) < 0) {
+ SCLogWarning(SC_ERR_INVALID_VALUE, "Invalid value for "
+ "interval: \"%s\". Resetting to %d.", interval,
+ STATS_MGMTT_TTS);
+ stats_tts = STATS_MGMTT_TTS;
+ }
int b;
int ret = ConfGetChildValueBool(stats, "decoder-events", &b);
#include "detect-engine-port.h"
#include "util-debug.h"
+#include "util-byte.h"
#include "util-print.h"
#include "util-var.h"
goto error;
}
- int cidr = atoi(mask);
- if (cidr < 0 || cidr > 32)
+ int cidr;
+ if (StringParseI32RangeCheck(&cidr, 10, 0, (const char *)mask, 0, 32) < 0)
goto error;
-
netmask = CIDRGet(cidr);
} else {
/* 1.2.3.4/255.255.255.0 format */
ip[mask - ip] = '\0';
mask++;
- int cidr = atoi(mask);
- if (cidr < 0 || cidr > 128)
- goto error;
+ int cidr;
+ if (StringParseI32RangeCheck(&cidr, 10, 0, (const char *)mask, 0, 128) < 0)
+ goto error;
r = inet_pton(AF_INET6, ip, &in6);
if (r <= 0)
#include "util-unittest.h"
#include "util-unittest-helper.h"
#include "util-print.h"
+#include "util-byte.h"
#include "util-profiling.h"
#include "util-validate.h"
goto error;
}
- int cidr = atoi(mask);
- if (cidr < 0 || cidr > 32)
+ int cidr;
+ if (StringParseI32RangeCheck(&cidr, 10, 0, (const char *)mask, 0, 32) < 0)
goto error;
dd->netmask = cidr;
goto error;
/* Format is cidr val */
- dd->netmask = atoi(mask);
+ if (StringParseU8RangeCheck(&dd->netmask, 10, 0,
+ (const char *)mask, 0, 128) < 0) {
+ goto error;
+ }
memcpy(dd->ip, &in6.s6_addr, sizeof(ip6addr));
} else {
}
if (insp_recursion_limit != NULL) {
- de_ctx->inspection_recursion_limit = atoi(insp_recursion_limit);
+ if (StringParseInt32(&de_ctx->inspection_recursion_limit, 10,
+ 0, (const char *)insp_recursion_limit) < 0) {
+ SCLogWarning(SC_ERR_INVALID_VALUE, "Invalid value for "
+ "detect-engine.inspection-recursion-limit: %s "
+ "resetting to %d", insp_recursion_limit,
+ DETECT_ENGINE_DEFAULT_INSPECTION_RECURSION_LIMIT);
+ de_ctx->inspection_recursion_limit =
+ DETECT_ENGINE_DEFAULT_INSPECTION_RECURSION_LIMIT;
+ }
} else {
de_ctx->inspection_recursion_limit =
DETECT_ENGINE_DEFAULT_INSPECTION_RECURSION_LIMIT;
if (de_ctx == NULL)
goto end;
- result = (de_ctx->inspection_recursion_limit == -1);
+ result = (de_ctx->inspection_recursion_limit == DETECT_ENGINE_DEFAULT_INSPECTION_RECURSION_LIMIT);
end:
if (de_ctx != NULL)
#include "flow-var.h"
#include "util-debug.h"
+#include "util-byte.h"
#include "util-unittest.h"
#include "util-unittest-helper.h"
}
/* ok, fill the id data */
- temp = atoi((char *)tmp_str);
-
- if (temp > DETECT_IPID_MAX) {
- SCLogError(SC_ERR_INVALID_VALUE, "invalid id option '%s'. The id option "
- "value must be in the range %u - %u",
- idstr, DETECT_IPID_MIN, DETECT_IPID_MAX);
+ if (StringParseU32RangeCheck(&temp, 10, 0, (const char *)tmp_str,
+ DETECT_IPID_MIN, DETECT_IPID_MAX) < 0) {
+ SCLogError(SC_ERR_INVALID_VALUE, "invalid id option '%s'", tmp_str);
return NULL;
}
#include "detect-xbits.h"
#include "detect-hostbits.h"
#include "util-spm.h"
+#include "util-byte.h"
#include "detect-engine-sigorder.h"
char fb_cmd_str[16] = "", fb_name[256] = "";
char hb_dir_str[16] = "";
enum VarTypes var_type = VAR_TYPE_NOT_SET;
- int expire = DETECT_XBITS_EXPIRE_DEFAULT;
+ uint32_t expire = DETECT_XBITS_EXPIRE_DEFAULT;
ret = DetectParsePcreExec(&parse_regex, rawstr, 0, 0, ov, MAX_SUBSTRINGS);
if (ret != 2 && ret != 3 && ret != 4 && ret != 5) {
return -1;
}
SCLogDebug("expire_str %s", expire_str);
- expire = atoi(expire_str);
- if (expire < 0) {
- SCLogError(SC_ERR_INVALID_VALUE, "expire must be positive. "
- "Got %d (\"%s\")", expire, expire_str);
+ if (StringParseUint32(&expire, 10, 0, (const char *)expire_str) < 0) {
+ SCLogError(SC_ERR_INVALID_VALUE, "Invalid value for "
+ "expire: \"%s\"", expire_str);
return -1;
}
if (expire == 0) {
#include "suricata-common.h"
#include "util-error.h"
#include "util-debug.h"
+#include "util-byte.h"
#include "util-ip.h"
#include "util-radix-tree.h"
#include "util-unittest.h"
SCLogDebug("%s, %s", ptrs[0], ptrs[1]);
- int c = atoi(ptrs[0]);
- if (c < 0 || c >= SREP_MAX_CATS) {
+ int c;
+ if (StringParseI32RangeCheck(&c, 10, 0, (const char *)ptrs[0], 0, SREP_MAX_CATS - 1) < 0)
return -1;
- }
*cat = (uint8_t)c;
strlcpy(shortname, ptrs[1], shortname_len);
if (strcmp(ptrs[0], "ip") == 0)
return 1;
- int c = atoi(ptrs[1]);
- if (c < 0 || c >= SREP_MAX_CATS) {
+ int c, v;
+ if (StringParseI32RangeCheck(&c, 10, 0, (const char *)ptrs[1], 0, SREP_MAX_CATS - 1) < 0)
return -1;
- }
- int v = atoi(ptrs[2]);
- if (v < 0 || v > SREP_MAX_VAL) {
+ if (StringParseI32RangeCheck(&v, 10, 0, (const char *)ptrs[2], 0, SREP_MAX_VAL) < 0)
return -1;
- }
if (strchr(ptrs[0], '/') != NULL) {
SRepCIDRAddNetblock(cidr_ctx, ptrs[0], c, v);
#include "util-runmodes.h"
#include "util-ioctl.h"
#include "util-ebpf.h"
+#include "util-byte.h"
#include "source-af-packet.h"
if (strcmp(threadsstr, "auto") == 0) {
aconf->threads = 0;
} else {
- aconf->threads = atoi(threadsstr);
+ if (StringParseInt32(&aconf->threads, 10, 0, (const char *)threadsstr) < 0) {
+ SCLogWarning(SC_ERR_INVALID_VALUE, "Invalid number of "
+ "threads, resetting to default");
+ aconf->threads = 0;
+ }
}
}
}
if (ConfGetChildValueWithDefault(if_root, if_default, "cluster-id", &tmpclusterid) != 1) {
aconf->cluster_id = (uint16_t)(cluster_id_auto++);
} else {
- aconf->cluster_id = (uint16_t)atoi(tmpclusterid);
+ if (StringParseInt32(&aconf->cluster_id, 10, 0, (const char *)tmpclusterid) < 0) {
+ SCLogWarning(SC_ERR_INVALID_VALUE, "Invalid cluster_id, resetting to 0");
+ aconf->cluster_id = 0;
+ }
SCLogDebug("Going to use cluster-id %" PRId32, aconf->cluster_id);
}
#include "util-debug.h"
#include "util-time.h"
#include "util-cpu.h"
+#include "util-byte.h"
#include "util-affinity.h"
#include "util-runmodes.h"
#include "util-device.h"
return NULL;
}
- /* device+5 is a pointer to the beginning of the stream id after the constant nt portion */
- conf->stream_id = atoi(device + 2);
+ /* device+2 is a pointer to the beginning of the stream id after the constant nt portion */
+ if (StringParseUint16(&conf->stream_id, 10, 0, device + 2) < 0) {
+ SCLogError(SC_ERR_INVALID_VALUE, "Invalid value for stream_id: %s", device + 2);
+ SCFree(conf);
+ return NULL;
+ }
/* Set the host buffer allowance for this stream
* Right now we just look at the global default - there is no per-stream hba configuration
#include "util-device.h"
#include "util-runmodes.h"
#include "util-ioctl.h"
+#include "util-byte.h"
#include "source-netmap.h"
ns->threads = 0;
ns->threads_auto = true;
} else {
- ns->threads = atoi(threadsstr);
+ if (StringParseUint16(&ns->threads, 10, 0, threadsstr) < 0) {
+ SCLogWarning(SC_ERR_INVALID_VALUE, "Invalid config value for "
+ "threads: %s, resetting to 0", threadsstr);
+ ns->threads = 0;
+ }
}
}
#include "util-runmodes.h"
#include "util-atomic.h"
#include "util-misc.h"
+#include "util-byte.h"
const char *RunModeIdsGetDefaultMode(void)
{
aconf->threads = 1;
} else {
if (threadsstr != NULL) {
- aconf->threads = atoi(threadsstr);
+ if (StringParseInt32(&aconf->threads, 10, 0, (const char *)threadsstr) < 0) {
+ SCLogWarning(SC_ERR_INVALID_VALUE, "Invalid value for "
+ "pcap.threads: %s, resetting to 1", threadsstr);
+ aconf->threads = 1;
+ }
}
}
if (aconf->threads == 0) {
#include "util-runmodes.h"
#include "util-device.h"
#include "util-ioctl.h"
+#include "util-byte.h"
#ifdef HAVE_PFRING
#include <pfring.h>
pfconf->threads = 1;
} else {
if (threadsstr != NULL) {
- pfconf->threads = atoi(threadsstr);
+ if (StringParseUint16(&pfconf->threads, 10, 0, threadsstr) < 0) {
+ SCLogWarning(SC_ERR_INVALID_VALUE, "Invalid value for "
+ "pfring.threads: '%s'. Resetting to 1.", threadsstr);
+ pfconf->threads = 1;
+ }
}
}
if (pfconf->threads == 0) {
} else if (ConfGet("pfring.cluster-id", &tmpclusterid) != 1) {
SCLogError(SC_ERR_INVALID_ARGUMENT,"Could not get cluster-id from config");
} else {
- pfconf->cluster_id = (uint16_t)atoi(tmpclusterid);
+ if (StringParseUint16(&pfconf->cluster_id, 10, 0, (const char *)tmpclusterid) < 0) {
+ SCLogWarning(SC_ERR_INVALID_VALUE, "Invalid value for "
+ "pfring.cluster_id: '%s'. Resetting to 1.", tmpclusterid);
+ pfconf->cluster_id = 1;
+ }
pfconf->flags |= PFRING_CONF_FLAGS_CLUSTER;
SCLogDebug("Going to use cluster-id %" PRId32, pfconf->cluster_id);
}
}
}
} else {
- pfconf->threads = atoi(threadsstr);
+ if (StringParseUint16(&pfconf->threads, 10, 0, (const char *)threadsstr) < 0) {
+ SCLogWarning(SC_ERR_INVALID_VALUE, "Invalid value for "
+ "pfring.threads: '%s'. Resetting to 1.", threadsstr);
+ pfconf->threads = 1;
+ }
}
}
if (pfconf->threads <= 0) {
/* command line value has precedence */
if (ConfGet("pfring.cluster-id", &tmpclusterid) == 1) {
- pfconf->cluster_id = (uint16_t)atoi(tmpclusterid);
+ if (StringParseUint16(&pfconf->cluster_id, 10, 0, (const char *)tmpclusterid) < 0) {
+ SCLogWarning(SC_ERR_INVALID_VALUE, "Invalid value for "
+ "pfring.cluster-id: '%s'. Resetting to 1.", tmpclusterid);
+ pfconf->cluster_id = 1;
+ }
pfconf->flags |= PFRING_CONF_FLAGS_CLUSTER;
SCLogDebug("Going to use command-line provided cluster-id %" PRId32,
pfconf->cluster_id);
SCLogError(SC_ERR_INVALID_ARGUMENT,
"Could not get cluster-id from config");
} else {
- pfconf->cluster_id = (uint16_t)atoi(tmpclusterid);
+ if (StringParseUint16(&pfconf->cluster_id, 10, 0, (const char *)tmpclusterid) < 0) {
+ SCLogWarning(SC_ERR_INVALID_VALUE, "Invalid value for "
+ "pfring.cluster-id: '%s'. Resetting to 1.", tmpclusterid);
+ pfconf->cluster_id = 1;
+ }
pfconf->flags |= PFRING_CONF_FLAGS_CLUSTER;
SCLogDebug("Going to use cluster-id %" PRId32, pfconf->cluster_id);
}
bool ips; /**< set to true if checksum_mode != NETMAP_COPY_MODE_NONE */
bool threads_auto;
- int threads;
+ uint16_t threads;
int copy_mode;
ChecksumValidationMode checksum_mode;
const char *bpf_filter;