]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb: Use hex_byte() in hex_to_data()
authorVolker Lendecke <vl@samba.org>
Mon, 4 Jan 2021 13:10:57 +0000 (14:10 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 8 Jan 2021 20:31:33 +0000 (20:31 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
ctdb/tools/ctdb.c

index e21d2d4b562c6ac96d317e562e274a8444ac2054..598ab4ff4b7e84b63d9a602e555d3fd01458b7b7 100644 (file)
@@ -591,17 +591,6 @@ static bool db_exists(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
        return true;
 }
 
-static int h2i(char h)
-{
-       if (h >= 'a' && h <= 'f') {
-               return h - 'a' + 10;
-       }
-       if (h >= 'A' && h <= 'F') {
-               return h - 'A' + 10;
-       }
-       return h - '0';
-}
-
 static int hex_to_data(const char *str, size_t len, TALLOC_CTX *mem_ctx,
                       TDB_DATA *out)
 {
@@ -621,7 +610,11 @@ static int hex_to_data(const char *str, size_t len, TALLOC_CTX *mem_ctx,
        }
 
        for (i=0; i<data.dsize; i++) {
-               data.dptr[i] = h2i(str[i*2]) << 4 | h2i(str[i*2+1]);
+               bool ok = hex_byte(&str[i*2], &data.dptr[i]);
+               if (!ok) {
+                       fprintf(stderr, "Invalid hex: %s\n", &str[i*2]);
+                       return EINVAL;
+               }
        }
 
        *out = data;