ctdb-server: Use wrapper for string to integer conversion
authorSwen Schillig <swen@linux.ibm.com>
Tue, 29 Jan 2019 12:07:56 +0000 (13:07 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 1 Mar 2019 00:32:11 +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/server/ctdb_recovery_helper.c

index 7fdcc2e5a29ea0414bb8fe84a44e6fa9415b3cba..57e12b4703738235d3d6c26de1cb9bc585441fe6 100644 (file)
@@ -30,6 +30,7 @@
 #include "lib/util/sys_rw.h"
 #include "lib/util/time.h"
 #include "lib/util/tevent_unix.h"
 #include "lib/util/sys_rw.h"
 #include "lib/util/time.h"
 #include "lib/util/tevent_unix.h"
+#include "lib/util/util.h"
 
 #include "protocol/protocol.h"
 #include "protocol/protocol_api.h"
 
 #include "protocol/protocol.h"
 #include "protocol/protocol_api.h"
@@ -2739,7 +2740,7 @@ int main(int argc, char *argv[])
        TALLOC_CTX *mem_ctx;
        struct tevent_context *ev;
        struct ctdb_client_context *client;
        TALLOC_CTX *mem_ctx;
        struct tevent_context *ev;
        struct ctdb_client_context *client;
-       int ret;
+       int ret = 0;
        struct tevent_req *req;
        uint32_t generation;
 
        struct tevent_req *req;
        uint32_t generation;
 
@@ -2750,7 +2751,11 @@ int main(int argc, char *argv[])
 
        write_fd = atoi(argv[1]);
        sockpath = argv[2];
 
        write_fd = atoi(argv[1]);
        sockpath = argv[2];
-       generation = (uint32_t)strtoul(argv[3], NULL, 0);
+       generation = (uint32_t)strtoul_err(argv[3], NULL, 0, &ret);
+       if (ret != 0) {
+               fprintf(stderr, "recovery: unable to initialize generation\n");
+               goto failed;
+       }
 
        mem_ctx = talloc_new(NULL);
        if (mem_ctx == NULL) {
 
        mem_ctx = talloc_new(NULL);
        if (mem_ctx == NULL) {