1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

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>
This commit is contained in:
Swen Schillig 2019-01-29 13:03:20 +01:00 committed by Jeremy Allison
parent 414bc3748b
commit e96bccc879

View 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;
}