diff options
author | Mattias Andrée <maandree@kth.se> | 2022-01-06 00:51:14 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-01-06 00:51:14 +0100 |
commit | df593680b8adf2ab6924ff38acbeb7b42977c9a0 (patch) | |
tree | 63f3c823e43213e6d72f00bc8575ea2fb505bdab /libblake_decode_hex.c | |
parent | First commit (diff) | |
download | libblake-df593680b8adf2ab6924ff38acbeb7b42977c9a0.tar.gz libblake-df593680b8adf2ab6924ff38acbeb7b42977c9a0.tar.bz2 libblake-df593680b8adf2ab6924ff38acbeb7b42977c9a0.tar.xz |
libblake_decode_hex: verify input
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libblake_decode_hex.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/libblake_decode_hex.c b/libblake_decode_hex.c index 4243d82..afdc31c 100644 --- a/libblake_decode_hex.c +++ b/libblake_decode_hex.c @@ -2,19 +2,24 @@ #include "common.h" size_t -libblake_decode_hex(const char *data, size_t n, void *out_) +libblake_decode_hex(const char *data, size_t n, void *out_, int *validp) { unsigned char *out = out_, value; size_t i, j = 0; int odd = 0; + *validp = 1; + if (!out) { for (i = 0; i < n && data[i]; i++) { if (isxdigit(data[i])) { j += (size_t)odd; odd ^= 1; + } else if (isgraph(data[i])) { + *validp = 0; } } + *validp &= !odd; return j; } @@ -28,8 +33,11 @@ libblake_decode_hex(const char *data, size_t n, void *out_) out[j++] |= value; odd = 0; } + } else if (isgraph(data[i])) { + *validp = 0; } } + *validp &= !odd; return j; } |