libopkg: make checksum_bin2hex() and checksum_hex2bin() cope with NULL
[oweals/opkg-lede.git] / libopkg / file_util.c
index 155d73b52be1ac81d88ebfd851c50c98ede6f012..b1d793023154ff5f7da0f9ef76efc6601454b718 100644 (file)
@@ -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++;