summaryrefslogtreecommitdiff
path: root/ctdb/protocol
diff options
context:
space:
mode:
authorSwen Schillig <swen@linux.ibm.com>2019-01-29 13:03:20 +0100
committerJeremy Allison <jra@samba.org>2019-03-01 00:32:10 +0000
commite96bccc879a675856b3a875db2d718445410caea (patch)
tree8fc364e953432ca0cf92a5a40f4a68816f7b493c /ctdb/protocol
parent414bc3748b6fbd54cbd50a0ff1f20cbe31b06ccc (diff)
downloadsamba-e96bccc879a675856b3a875db2d718445410caea.tar.gz
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 <swen@linux.ibm.com> Reviewed-by: Ralph Böhme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'ctdb/protocol')
-rw-r--r--ctdb/protocol/protocol_util.c11
1 files changed, 6 insertions, 5 deletions
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;
}