From 060a84370d85e09cc888927d6eb67167fd1900aa Mon Sep 17 00:00:00 2001 From: "Rule Timothy (VM/EMT3)" Date: Wed, 3 Apr 2024 14:02:59 +0200 Subject: [PATCH] Fix dse_yaml_get_uint() and dse_yaml_get_int(). Signed-off-by: Rule Timothy (VM/EMT3) --- dse/clib/util/yaml.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dse/clib/util/yaml.c b/dse/clib/util/yaml.c index 491f0e8..b9f84cc 100644 --- a/dse/clib/util/yaml.c +++ b/dse/clib/util/yaml.c @@ -223,9 +223,10 @@ DLL_PUBLIC int dse_yaml_get_uint( if (_scalar == NULL) return EINVAL; /* Integer? */ errno = 0; - unsigned int _uint = strtol(_scalar, NULL, 10); - if (errno == 0) { - *value = _uint; + char* endptr = NULL; + int _int = strtol(_scalar, &endptr, 10); + if (errno == 0 && _scalar != endptr && *endptr == '\0' && _int >= 0) { + *value = (unsigned int)_int; return 0; } /* Fallback to bool? */ @@ -256,8 +257,9 @@ DLL_PUBLIC int dse_yaml_get_int(YamlNode* node, const char* name, int* value) return EINVAL; /* Integer? */ errno = 0; - int _int = strtol(_scalar, NULL, 10); - if (errno == 0) { + char* endptr = NULL; + int _int = strtol(_scalar, &endptr, 10); + if (errno == 0 && _scalar != endptr && *endptr == '\0') { *value = _int; return 0; }