diff options
author | Volker Lendecke <vl@samba.org> | 2021-01-04 13:50:23 +0100 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2021-01-08 20:31:33 +0000 |
commit | ad081bf2ddb60dfd5b8f838741e9de0710598b6a (patch) | |
tree | 5693fbd3dbba13a6b75e8d20c431ba3704e4c3b6 /lib/tdb | |
parent | c8d9ce3f7c8c486ab21e320a0adcb71311dcb453 (diff) | |
download | samba-ad081bf2ddb60dfd5b8f838741e9de0710598b6a.tar.gz |
tdb: Use hex_byte() in read_data()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib/tdb')
-rw-r--r-- | lib/tdb/tools/tdbrestore.c | 41 |
1 files changed, 10 insertions, 31 deletions
diff --git a/lib/tdb/tools/tdbrestore.c b/lib/tdb/tools/tdbrestore.c index 9d5146272cc..3312cf74d83 100644 --- a/lib/tdb/tools/tdbrestore.c +++ b/lib/tdb/tools/tdbrestore.c @@ -62,29 +62,7 @@ static int read_linehead(FILE *f) return num_bytes; } -static int read_hex(void) { - int c; - c = getchar(); - if (c == EOF) { - fprintf(stderr, "Unexpected EOF in data\n"); - return -1; - } else if (c == '"') { - fprintf(stderr, "Unexpected \\\" sequence\n"); - return -1; - } else if ('0' <= c && c <= '9') { - return c - '0'; - } else if ('A' <= c && c <= 'F') { - return c - 'A' + 10; - } else if ('a' <= c && c <= 'f') { - return c - 'a' + 10; - } else { - fprintf(stderr, "Invalid hex: %c\n", c); - return -1; - } -} - static int read_data(FILE *f, TDB_DATA *d, size_t size) { - int c, low, high; size_t i; d->dptr = (unsigned char *)malloc(size); @@ -94,25 +72,26 @@ static int read_data(FILE *f, TDB_DATA *d, size_t size) { d->dsize = size; for (i=0; i<size; i++) { - c = getc(f); + int c = getc(f); if (c == EOF) { fprintf(stderr, "Unexpected EOF in data\n"); return 1; } else if (c == '"') { return 0; } else if (c == '\\') { - high = read_hex(); - if (high < 0) { + char in[3] = {0}; + size_t n; + bool ok; + + n = fread(in, 1, 2, stdin); + if (n != 2) { return -1; } - high = high << 4; - assert(high == (high & 0xf0)); - low = read_hex(); - if (low < 0) { + ok = hex_byte(in, &d->dptr[i]); + if (!ok) { + fprintf(stderr, "Invalid hex: %s\n", in); return -1; } - assert(low == (low & 0x0f)); - d->dptr[i] = (low|high); } else { d->dptr[i] = c; } |