ctdb-utils: Use wrapper for string to integer conversion
authorSwen Schillig <swen@linux.ibm.com>
Wed, 30 Jan 2019 09:28:52 +0000 (10:28 +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/utils/ceph/ctdb_mutex_ceph_rados_helper.c

index 7ef76c26e02826eac43f49d37d69a244cb16ab40..a43855008c031b9d2f9aeaa6e9624fe3ec8d7098 100644 (file)
@@ -301,10 +301,14 @@ int main(int argc, char *argv[])
        cmr_state->pool_name = argv[3];
        cmr_state->object = argv[4];
        if (argc == 6) {
+               int error = 0;
                /* optional lock duration provided */
                char *endptr = NULL;
-               cmr_state->lock_duration_s = strtoull(argv[5], &endptr, 0);
-               if ((endptr == argv[5]) || (*endptr != '\0')) {
+               cmr_state->lock_duration_s = strtoull_err(argv[5],
+                                                         &endptr,
+                                                         0,
+                                                         &error);
+               if ((endptr == argv[5]) || (*endptr != '\0') || (error != 0)) {
                        fprintf(stdout, CTDB_MUTEX_STATUS_ERROR);
                        ret = -EINVAL;
                        goto err_ctx_cleanup;