From: Jo-Philipp Wich Date: Wed, 15 Feb 2017 22:42:58 +0000 (+0100) Subject: libopkg: make checksum_bin2hex() and checksum_hex2bin() cope with NULL X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=55a9337ba2641555623b3faa5e2dc6607b0ba0f0;p=oweals%2Fopkg-lede.git 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 --- 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++;