tools/ctdb: Improve error checking when parsing node string
authorMartin Schwenke <martin@meltin.net>
Fri, 22 Nov 2013 02:57:31 +0000 (13:57 +1100)
committerAmitay Isaacs <amitay@gmail.com>
Mon, 25 Nov 2013 03:25:45 +0000 (14:25 +1100)
If a node isn't numeric then it is silently converted to 0.

Signed-off-by: Martin Schwenke <martin@meltin.net>
tools/ctdb.c

index 3db2668e1b0cacecfea67ee9fd72e7ae91a9ad42..7b046c40f4ea444245e7e6ef4a48c809a6caccb5 100644 (file)
@@ -223,7 +223,14 @@ static bool parse_nodestring(struct ctdb_context *ctdb,
                        tok = strtok(ns, ",");
                        while (tok != NULL) {
                                uint32_t pnn;
-                               i = (uint32_t)strtoul(tok, NULL, 0);
+                               char *endptr;
+                               i = (uint32_t)strtoul(tok, &endptr, 0);
+                               if (i == 0 && tok == endptr) {
+                                       DEBUG(DEBUG_ERR,
+                                             ("Invalid node %s\n", tok));
+                                       talloc_free(tmp_ctx);
+                                       exit(ERR_NONODE);
+                               }
                                if (i >= nodemap->num) {
                                        DEBUG(DEBUG_ERR, ("Node %u does not exist\n", i));
                                        talloc_free(tmp_ctx);