From: Thomas Egerer Date: Wed, 25 Mar 2020 17:01:37 +0000 (+0100) Subject: settings: Use strtoul(3) for settings to int conversion X-Git-Tag: 5.8.4~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=99bef7b686970d3dae3130fb5ca2b856400a4f12;p=thirdparty%2Fstrongswan.git settings: Use strtoul(3) for settings to int conversion strtol(3) accepts values in the range of [LONG_MIN;LONG_MAX]. Based on the architecture (32 or 64 bits), these values expand to either 0x8000000000000000/0x7fffffffffffffff for 64-bit builds, or 0x80000000/0x7fffffff for 32-bit builds. The behavior when retrieving non-default values for charon.spi_min or charon.spi_max, for example, depends on the architecture of the target platform. While 0xC000001/0xCFFFFFFE work fine on a 64-bit build, on a 32-bit build, due to the use of strtol(3), an ERANGE causes get_int() to return the default values. By using strtoul(3) the default is only returned if the input value exceeds 32 or 64 bits, based on the platform. Negative values are still parsed correctly. Signed-off-by: Thomas Egerer --- diff --git a/src/libstrongswan/settings/settings.c b/src/libstrongswan/settings/settings.c index 44d035fac4..b67b00e514 100644 --- a/src/libstrongswan/settings/settings.c +++ b/src/libstrongswan/settings/settings.c @@ -611,7 +611,7 @@ inline int settings_value_as_int(char *value, int def) { /* manually detect 0x prefix as we want to avoid octal encoding */ base = 16; } - intval = strtol(value, &end, base); + intval = strtoul(value, &end, base); if (errno == 0 && *end == 0 && end != value) { return intval;