diff --git a/src/libsodium/sodium/codecs.c b/src/libsodium/sodium/codecs.c index 9d82d03f..7e203a5c 100644 --- a/src/libsodium/sodium/codecs.c +++ b/src/libsodium/sodium/codecs.c @@ -86,6 +86,9 @@ sodium_hex2bin(unsigned char *const bin, const size_t bin_maxlen, if (hex_end != NULL) { *hex_end = &hex[hex_pos]; } + if (ret != 0) { + bin_pos = (size_t) 0U; + } if (bin_len != NULL) { *bin_len = bin_pos; } @@ -208,6 +211,7 @@ sodium_bin2base64(char * const b64, const size_t b64_maxlen, b64[b64_pos++] = (char) b64_byte_to_char((acc << (6 - acc_len)) & 0x3F); } } + assert(b64_pos <= b64_len); while (b64_pos < b64_len) { b64[b64_pos++] = '='; } @@ -298,6 +302,9 @@ sodium_base642bin(unsigned char * const bin, const size_t bin_maxlen, ret = _sodium_base642bin_skip_padding(b64, b64_len, &b64_pos, ignore, acc_len / 2); } + if (ret != 0) { + bin_pos = (size_t) 0U; + } if (bin_len != NULL) { *bin_len = bin_pos; } diff --git a/test/default/sodium_utils.c b/test/default/sodium_utils.c index f0dee6bc..09c22544 100644 --- a/test/default/sodium_utils.c +++ b/test/default/sodium_utils.c @@ -117,8 +117,8 @@ main(void) b64 = "VGhpcyBpcyBhIGpvdXJu" "\n" "ZXkgaW50by" " " "Bzb3VuZA=="; memset(buf4, '*', sizeof buf4); - sodium_base642bin(buf4, sizeof buf4, b64, strlen(b64), "\n\r ", &bin_len, - &b64_end, sodium_base64_VARIANT_ORIGINAL); + assert(sodium_base642bin(buf4, sizeof buf4, b64, strlen(b64), "\n\r ", &bin_len, + &b64_end, sodium_base64_VARIANT_ORIGINAL) == -1); buf4[bin_len] = 0; printf("[%s]\n", (const char *) buf4); printf("[%s]\n", b64_end); diff --git a/test/default/sodium_utils.exp b/test/default/sodium_utils.exp index f7c9f5d7..233dc687 100644 --- a/test/default/sodium_utils.exp +++ b/test/default/sodium_utils.exp @@ -23,7 +23,7 @@ YWJj YQ YWI YWJj -[This] +[] [BpcyBhIGpvdXJu ZXkgaW50by Bzb3VuZA==] [This is a journey into sound]