Commit ce2b4195 authored by Philipp Schafft's avatar Philipp Schafft 🦁

Fix: Fixes a number of empty string segfaults in config parser

This fixes a number of segfault happening in case config tags are
empty. This patch also adds warnings for most cases.

Please test for any regressions.
This should likely be ported to 2.4.4 as well.

Closes: #2265
parent 70265c46
This diff is collapsed.
......@@ -565,6 +565,35 @@ int util_str_to_loglevel(const char *str) {
return atoi(str);
}
int util_str_to_int(const char *str, const int default_value)
{
/* consider NULL and empty strings default */
if (!str || !*str)
return default_value;
return atoi(str);
}
unsigned int util_str_to_unsigned_int(const char *str, const unsigned int default_value)
{
long int val;
char *rem = NULL;
/* consider NULL and empty strings default */
if (!str || !*str)
return default_value;
val = strtol(str, &rem, 10);
/* There is a left over */
if (rem && *rem)
return default_value;
if (val < 0)
return default_value;
return (unsigned int)(unsigned long int)val;
}
/* TODO, FIXME: handle memory allocation errors better. */
static inline void _build_headers_loop(char **ret, size_t *len, ice_config_http_header_t *header, int status) {
size_t headerlen;
......
......@@ -51,6 +51,8 @@ util_hostcheck_type util_hostcheck(const char *hostname);
int util_str_to_bool(const char *str);
int util_str_to_loglevel(const char *str);
int util_str_to_int(const char *str, const int default_value);
unsigned int util_str_to_unsigned_int(const char *str, const unsigned int default_value);
char *util_url_unescape(const char *src);
char *util_url_escape(const char *src);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment