From: Swen Schillig Date: Tue, 29 Jan 2019 12:03:20 +0000 (+0100) Subject: ctdb-protocol: Use wrapper for string to integer conversion X-Git-Tag: talloc-2.2.0~230 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e96bccc879a675856b3a875db2d718445410caea;p=thirdparty%2Fsamba.git ctdb-protocol: Use wrapper for string to integer conversion In order to detect an value overflow error during the string to integer conversion with strtoul/strtoull, the errno variable must be set to zero before the execution and checked after the conversion is performed. This is achieved by using the wrapper function strtoul_err and strtoull_err. Signed-off-by: Swen Schillig Reviewed-by: Ralph Böhme Reviewed-by: Jeremy Allison --- diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c index 75427e44f50..99dbe82404d 100644 --- a/ctdb/protocol/protocol_util.c +++ b/ctdb/protocol/protocol_util.c @@ -26,6 +26,7 @@ #include "protocol.h" #include "protocol_util.h" +#include "lib/util/util.h" static struct { enum ctdb_runstate runstate; @@ -286,8 +287,8 @@ int ctdb_sock_addr_from_string(const char *str, return EINVAL; } - port = strtoul(p+1, &endp, 10); - if (endp == p+1 || *endp != '\0') { + port = strtoul_err(p+1, &endp, 10, &ret); + if (endp == p+1 || *endp != '\0' || ret != 0) { /* Empty string or trailing garbage */ return EINVAL; } @@ -309,7 +310,7 @@ int ctdb_sock_addr_mask_from_string(const char *str, unsigned int m; char *endp = NULL; ssize_t len; - bool ret; + int ret = 0; if (addr == NULL || mask == NULL) { return EINVAL; @@ -325,8 +326,8 @@ int ctdb_sock_addr_mask_from_string(const char *str, return EINVAL; } - m = strtoul(p+1, &endp, 10); - if (endp == p+1 || *endp != '\0') { + m = strtoul_err(p+1, &endp, 10, &ret); + if (endp == p+1 || *endp != '\0' || ret != 0) { /* Empty string or trailing garbage */ return EINVAL; }