ctdb-protocol: Use wrapper for string to integer conversion
authorSwen Schillig <swen@linux.ibm.com>
Tue, 29 Jan 2019 12:03:20 +0000 (13:03 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 1 Mar 2019 00:32:10 +0000 (00:32 +0000)
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 <swen@linux.ibm.com>
Reviewed-by: Ralph Böhme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
ctdb/protocol/protocol_util.c

index 75427e44f50fa370e45b1179296c8ec037592438..99dbe82404d3ac7b7dd6dcc2ab5cce4fdb5299b3 100644 (file)
@@ -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;
        }