From fef2a7ca0a87dc3de25480b8070f8090d5f1cb09 Mon Sep 17 00:00:00 2001 From: Swen Schillig Date: Mon, 28 Jan 2019 13:12:09 +0100 Subject: groupdb: Use wrapper for string to integer conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- source3/groupdb/mapping.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source3/groupdb/mapping.c') diff --git a/source3/groupdb/mapping.c b/source3/groupdb/mapping.c index 43722e777d4..77eb0d6e5cd 100644 --- a/source3/groupdb/mapping.c +++ b/source3/groupdb/mapping.c @@ -208,6 +208,7 @@ int smb_create_group(const char *unix_group, gid_t *new_gid) char *add_script = NULL; int ret = -1; int fd = 0; + int error = 0; *new_gid = 0; @@ -244,7 +245,15 @@ int smb_create_group(const char *unix_group, gid_t *new_gid) nread = read(fd, output, sizeof(output)-1); if (nread > 0) { output[nread] = '\0'; - *new_gid = (gid_t)strtoul(output, NULL, 10); + *new_gid = (gid_t)strtoul_err(output, + NULL, + 10, + &error); + if (error != 0) { + *new_gid = 0; + close(fd); + return -1; + } } close(fd); -- cgit v1.2.1