diff options
author | Corubba Smith <corubba@gmx.de> | 2025-03-12 15:55:16 +0100 |
---|---|---|
committer | Florian Westphal <fw@strlen.de> | 2025-03-12 16:22:34 +0100 |
commit | a6229ae0bbeb8fcb7f9ee5d1dddaae98c0c71176 (patch) | |
tree | 970bc9a2610b3a9091e8d127fbee16d05bc526c5 /src/ulogd.c | |
parent | 0ac16e540283e2fa6c89292a416448c944bd3483 (diff) |
ulogd: improve integer option parsing
The `value` union member in `struct config_entry` is declared as `int`
since basically the beginning in e07722e46001 ("config stuff added").
The parsing was switched from the original `atoi()` in 015849995f7f
("Fix hexadecimal parsing in config file") to `strtoul()`.
Switch the function for parsing to the signed `strtol()` variant since
the result will be stored in a signed int, and it makes sense to support
negative numbers. Detect when `strtol()` does not properly consume the
whole argument and return a new format error. Also check the numerical
value to make sure the signed int does not overflow, in which case
a new range error is returned.
Unfortunately there is no `strtoi()` which would do the proper range
check itself, so the intermediate `long` and range-check for `int` is
required. I also considered changing the `value` union member from
`int` to `long`, which would make it possible to use the parsed value
as-is. But since this is part of the api towards plugins (including
third party) such a potentially breaking change felt unwarranted. This
also means that still only 16bit integer values are *guaranteed* to
work, although most platforms use bigger widths for int.
Signed-off-by: Corubba Smith <corubba@gmx.de>
Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'src/ulogd.c')
-rw-r--r-- | src/ulogd.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/ulogd.c b/src/ulogd.c index 7260aeb..c844767 100644 --- a/src/ulogd.c +++ b/src/ulogd.c @@ -293,6 +293,16 @@ int ulogd_parse_configfile(const char *section, struct config_keyset *ce) else ulogd_log(ULOGD_ERROR, "string value is too long\n"); break; + case -ERRINTFORMAT: + ulogd_log(ULOGD_ERROR, + "integer has invalid format for key \"%s\"\n", + config_errce->key); + break; + case -ERRINTRANGE: + ulogd_log(ULOGD_ERROR, + "integer is out of range for key \"%s\"\n", + config_errce->key); + break; } return ULOGD_IRET_ERR; |