#define _THREAD_AFFINITY
#include "util-affinity.h"
#include "util-cpu.h"
+#include "util-byte.h"
#include "conf.h"
#include "threads.h"
#include "queue.h"
node = ConfNodeLookupChild(affinity->head.tqh_first, "threads");
if (node != NULL) {
- taf->nb_threads = atoi(node->val);
+ if (StringParseUint32(&taf->nb_threads, 10, 0, (const char *)node->val) < 0) {
+ FatalError(SC_ERR_INVALID_ARGUMENT, "invalid value for threads "
+ "count: '%s'", node->val);
+ }
if (! taf->nb_threads) {
SCLogError(SC_ERR_INVALID_ARGUMENT, "bad value for threads count");
exit(EXIT_FAILURE);
#include "util-error.h"
#include "util-debug.h"
#include "util-fmemopen.h"
+#include "util-byte.h"
/* Regex to parse the classtype argument from a Signature. The first substring
* holds the classtype name, the second substring holds the classtype the
char ct_name[CLASSTYPE_NAME_MAX_LEN];
char ct_desc[CLASSTYPE_DESC_MAX_LEN];
char ct_priority_str[16];
- int ct_priority = 0;
+ uint32_t ct_priority = 0;
uint16_t ct_id = index;
SCClassConfClasstype *ct_new = NULL;
SCLogInfo("pcre_copy_substring() failed");
goto error;
}
- if (strlen(ct_priority_str) == 0) {
+ if (StringParseUint32(&ct_priority, 10, 0, (const char *)ct_priority_str) < 0) {
goto error;
}
- ct_priority = atoi(ct_priority_str);
-
/* Create a new instance of the parsed Classtype string */
ct_new = SCClassConfAllocClasstype(ct_id, ct_name, ct_desc, ct_priority);
if (ct_new == NULL)
#include "util-error.h"
#include "util-debug.h"
#include "util-cpu.h"
+#include "util-byte.h"
/**
* Ok, if they should use sysconf, check that they have the macro's
return (uint16_t)nprocs;
#elif OS_WIN32
- long nprocs = -1;
- const char* envvar = getenv("NUMBER_OF_PROCESSORS");
- nprocs = (NULL != envvar) ? atoi(envvar) : 0;
+ int64_t nprocs = 0;
+ const char* envvar = getenv("NUMBER_OF_PROCESSORS");
+ if (envvar != NULL) {
+ if (StringParseInt64(&nprocs, 10, 0, envvar) < 0) {
+ SCLogWarning(SC_ERR_INVALID_VALUE, "Invalid value for number of "
+ "processors: %s", envvar);
+ return 0;
+ }
+ }
if (nprocs < 1) {
SCLogError(SC_ERR_SYSCALL, "Couldn't retrieve the number of cpus "
"configured from the NUMBER_OF_PROCESSORS environment variable");
#include "suricata-common.h"
#include "config.h"
#include "util-host-info.h"
+#include "util-byte.h"
#ifndef OS_WIN32
#include <sys/utsname.h>
pcre_get_substring_list(kuname.release, ov, ret, &list);
- kmajor = atoi(list[1]);
- kminor = atoi(list[2]);
+ bool err = false;
+ if (StringParseInt32(&kmajor, 10, 0, (const char *)list[1]) < 0) {
+ SCLogError(SC_ERR_INVALID_VALUE, "Invalid value for kmajor: '%s'", list[1]);
+ err = true;
+ }
+ if (StringParseInt32(&kminor, 10, 0, (const char *)list[2]) < 0) {
+ SCLogError(SC_ERR_INVALID_VALUE, "Invalid value for kminor: '%s'", list[2]);
+ err = true;
+ }
pcre_free_substring_list(list);
pcre_free_study(version_regex_study);
pcre_free(version_regex);
+ if (err)
+ goto error;
+
if (kmajor > major)
return 1;
if (kmajor == major && kminor >= minor)
#include "util-debug.h"
#include "util-ip.h"
#include "util-radix-tree.h"
+#include "util-byte.h"
#include "stream-tcp-private.h"
#include "stream-tcp-reassemble.h"
SCRadixAddKeyIPV4((uint8_t *)ipv4_addr, sc_hinfo_tree,
(void *)user_data);
} else {
- netmask_value = atoi(netmask_str);
- if (netmask_value < 0 || netmask_value > 32) {
+ if (StringParseI32RangeCheck(&netmask_value, 10, 0, (const char *)netmask_str, 0, 32) < 0) {
SCLogError(SC_ERR_INVALID_IP_NETBLOCK, "Invalid IPV4 Netblock");
SCHInfoFreeUserDataOSPolicy(user_data);
SCFree(ipv4_addr);
SCRadixAddKeyIPV6((uint8_t *)ipv6_addr, sc_hinfo_tree,
(void *)user_data);
} else {
- netmask_value = atoi(netmask_str);
- if (netmask_value < 0 || netmask_value > 128) {
+ if (StringParseI32RangeCheck(&netmask_value, 10, 0, (const char *)netmask_str, 0, 128) < 0) {
SCLogError(SC_ERR_INVALID_IP_NETBLOCK, "Invalid IPV6 Netblock");
SCHInfoFreeUserDataOSPolicy(user_data);
SCFree(ipv6_addr);
#include "suricata-common.h"
#include "util-ip.h"
+#include "util-byte.h"
/** \brief determine if a string is a valid ipv4 address
* \retval bool is addr valid?
addr[dots][alen] = '\0';
for (int x = 0; x < 4; x++) {
- int a = atoi(addr[x]);
- if (a < 0 || a >= 256) {
- SCLogDebug("out of range");
+ uint8_t a;
+ if (StringParseUint8(&a, 10, 0, (const char *)addr[x]) < 0) {
+ SCLogDebug("invalid value for address byte: %s", addr[x]);
return false;
}
}
#include "suricata-common.h" /* errno.h, string.h, etc. */
#include "util-log-redis.h"
#include "util-logopenfile.h"
+#include "util-byte.h"
#ifdef HAVE_LIBHIREDIS
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating redis server string");
exit(EXIT_FAILURE);
}
- log_ctx->redis_setup.port = atoi(redis_port);
+ if (StringParseUint16(&log_ctx->redis_setup.port, 10, 0, (const char *)redis_port) < 0) {
+ FatalError(SC_ERR_INVALID_VALUE, "Invalid value for redis port: %s", redis_port);
+ }
log_ctx->Close = SCLogFileCloseRedis;
#ifdef HAVE_LIBEVENT
char copystr[16];
strlcpy(copystr, lnode->val, 16);
-
- ByteExtractStringUint8(&start, 10, 0, copystr);
- ByteExtractStringUint8(&end, 10, 0, strchr(copystr, '-') + 1);
-
+ if (StringParseUint8(&start, 10, 0, (const char *)copystr) < 0) {
+ FatalError(SC_ERR_INVALID_VALUE, "Napatech invalid"
+ " worker range start: '%s'", copystr);
+ }
+ char *end_str = strchr(copystr, '-');
+ if ((end_str == NULL) || (end_str != NULL && StringParseUint8(&end,
+ 10, 0, (const char *) (end_str + 1)) < 0)) {
+ FatalError(SC_ERR_INVALID_VALUE, "Napatech invalid"
+ " worker range end: '%s'", (end_str != NULL) ? (const char *)(end_str + 1) : "Null");
+ }
+ if (end < start) {
+ FatalError(SC_ERR_INVALID_VALUE, "Napatech invalid"
+ " worker range start: '%s' is greater than end: '%s'", start, end);
+ }
worker_count = end - start + 1;
} else {
int set_cpu_affinity = 0;
ConfNode *ntstreams;
uint16_t stream_id = 0;
- uint16_t start = 0;
- uint16_t end = 0;
+ uint8_t start = 0;
+ uint8_t end = 0;
for (uint16_t i = 0; i < MAX_STREAMS; ++i) {
stream_config[i].stream_id = 0;
char copystr[16];
strlcpy(copystr, stream->val, 16);
- ByteExtractStringUint16(&start, 10, 0, copystr);
- ByteExtractStringUint16(&end, 10, 0, strchr(copystr, '-') + 1);
+ if (StringParseUint8(&start, 10, 0, (const char *)copystr) < 0) {
+ FatalError(SC_ERR_INVALID_VALUE, "Napatech invalid "
+ "stream id start: '%s'", copystr);
+ }
+ char *end_str = strchr(copystr, '-');
+ if ((end_str == NULL) || (end_str != NULL && StringParseUint8(&end,
+ 10, 0, (const char *) (end_str + 1)) < 0)) {
+ FatalError(SC_ERR_INVALID_VALUE, "Napatech invalid "
+ "stream id end: '%s'", (end_str != NULL) ? (const char *)(end_str + 1) : "Null");
+ }
} else {
if (stream_spec == CONFIG_SPECIFIER_RANGE) {
SCLogError(SC_ERR_NAPATECH_PARSE_CONFIG,
exit(EXIT_FAILURE);
}
stream_spec = CONFIG_SPECIFIER_INDIVIDUAL;
- ByteExtractStringUint16(&stream_config[instance_cnt].stream_id, 10, 0, stream->val);
+ if (StringParseUint16(&stream_config[instance_cnt].stream_id,
+ 10, 0, (const char *)stream->val) < 0) {
+ FatalError(SC_ERR_INVALID_VALUE, "Napatech invalid "
+ "stream id: '%s'", stream->val);
+ }
start = stream_config[instance_cnt].stream_id;
end = stream_config[instance_cnt].stream_id;
}
#include "suricata.h"
#include "util-privs.h"
+#include "util-byte.h"
#ifdef HAVE_LIBCAP_NG
/* Get the user ID */
if (isdigit((unsigned char)user_name[0]) != 0) {
- userid = atoi(user_name);
+ if (ByteExtractStringUint32(&userid, 10, 0, (const char *)user_name) < 0) {
+ FatalError(SC_ERR_UID_FAILED, "invalid user id value: '%s'", user_name);
+ }
pw = getpwuid(userid);
if (pw == NULL) {
SCLogError(SC_ERR_UID_FAILED, "unable to get the user ID, "
struct group *gp;
if (isdigit((unsigned char)group_name[0]) != 0) {
- groupid = atoi(group_name);
+ if (ByteExtractStringUint32(&groupid, 10, 0, (const char *)group_name) < 0) {
+ FatalError(SC_ERR_GID_FAILED, "invalid group id: '%s'", group_name);
+ }
} else {
gp = getgrnam(group_name);
if (gp == NULL) {
/* Get the group ID */
if (isdigit((unsigned char)group_name[0]) != 0) {
- grpid = atoi(group_name);
+ if (ByteExtractStringUint32(&grpid, 10, 0, (const char *)group_name) < 0) {
+ FatalError(SC_ERR_GID_FAILED, "invalid group id: '%s'", group_name);
+ }
} else {
gp = getgrnam(group_name);
if (gp == NULL) {
#include "suricata-common.h"
#include "util-proto-name.h"
+#include "util-byte.h"
/** Lookup array to hold the information related to known protocol
* in /etc/protocols */
if (proto_ch == NULL)
continue;
- int proto = atoi(proto_ch);
- if (proto >= 255)
+ uint8_t proto;
+ if (StringParseUint8(&proto, 10, 0, (const char *)proto_ch) < 0)
continue;
char *cname = strtok_r(NULL, " \t", &ptr);
#include "util-ip.h"
#include "util-unittest.h"
#include "util-memcmp.h"
+#include "util-byte.h"
/**
* \brief Allocates and returns a new instance of SCRadixUserData.
/* Does it have a mask? */
if (NULL != (mask_str = strchr(ip_str, '/'))) {
- int cidr;
+ uint8_t cidr;
*(mask_str++) = '\0';
/* Dotted type netmask not supported (yet) */
}
/* Get binary values for cidr mask */
- cidr = atoi(mask_str);
- if ((cidr < 0) || (cidr > 32)) {
+ if (StringParseU8RangeCheck(&cidr, 10, 0, (const char *)mask_str, 0, 32) < 0) {
return NULL;
}
+
netmask = (uint8_t)cidr;
}
/* Does it have a mask? */
if (NULL != (mask_str = strchr(ip_str, '/'))) {
- int cidr;
+ uint8_t cidr;
*(mask_str++) = '\0';
/* Dotted type netmask not supported (yet) */
}
/* Get binary values for cidr mask */
- cidr = atoi(mask_str);
- if ((cidr < 0) || (cidr > 128)) {
+ if (StringParseU8RangeCheck(&cidr, 10, 0, (const char *)mask_str, 0, 128) < 0) {
return NULL;
}
+
netmask = (uint8_t)cidr;
}