From 55a9337ba2641555623b3faa5e2dc6607b0ba0f0 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 15 Feb 2017 23:42:58 +0100 Subject: [PATCH] libopkg: make checksum_bin2hex() and checksum_hex2bin() cope with NULL Those functions may be called with a NULL source pointer, especially during pkg_merge(), so allow that to keep call sites simple. Signed-off-by: Jo-Philipp Wich --- libopkg/file_util.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libopkg/file_util.c b/libopkg/file_util.c index 155d73b..b1d7930 100644 --- a/libopkg/file_util.c +++ b/libopkg/file_util.c @@ -241,7 +241,7 @@ char *checksum_bin2hex(const char *src, size_t len) 'c', 'd', 'e', 'f' }; - if (len > 32) + if (!s || len > 32) return NULL; for (p = buf; len > 0; s++, len--) { @@ -261,6 +261,11 @@ char *checksum_hex2bin(const char *src, size_t *len) const unsigned char *s = (unsigned char *)src; static unsigned char buf[32]; + if (!src) { + *len = 0; + return NULL; + } + while (isspace(*src)) src++; -- 2.25.1