Skip to content

Commit

Permalink
found some more places assuming null terminator
Browse files Browse the repository at this point in the history
  • Loading branch information
graebm committed Feb 15, 2025
1 parent 6f10b1d commit f1676e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
16 changes: 9 additions & 7 deletions tests/encoding_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,25 +490,25 @@ static int s_base64_encoding_test_roundtrip(struct aws_allocator *allocator, voi
}
struct aws_byte_cursor original_data = aws_byte_cursor_from_array(test_data, sizeof(test_data));

uint8_t test_hex[65] = {0};
struct aws_byte_buf hex = aws_byte_buf_from_empty_array(test_hex, sizeof(test_hex));
struct aws_byte_buf hex;
aws_byte_buf_init(&hex, allocator, 65);

uint8_t test_b64[128] = {0};
struct aws_byte_buf b64_data = aws_byte_buf_from_empty_array(test_b64, sizeof(test_b64));

aws_base64_encode(&original_data, &b64_data);
b64_data.len--;

uint8_t decoded_data[32] = {0};
struct aws_byte_buf decoded_buf = aws_byte_buf_from_empty_array(decoded_data, sizeof(decoded_data));
struct aws_byte_buf decoded_buf;
aws_byte_buf_init(&decoded_buf, allocator, 32);

struct aws_byte_cursor b64_cur = aws_byte_cursor_from_buf(&b64_data);
aws_base64_decode(&b64_cur, &decoded_buf);

if (memcmp(decoded_buf.buffer, original_data.ptr, decoded_buf.len) != 0) {
aws_hex_encode(&original_data, &hex);
fprintf(stderr, "Base64 round-trip failed\n");
fprintf(stderr, "Original: %s\n", (char *)test_hex);
fprintf(stderr, "Original: " PRInSTR "\n", AWS_BYTE_BUF_PRI(hex));
fprintf(stderr, "Base64 : ");
for (size_t i = 0; i < sizeof(test_b64); i++) {
if (!test_b64[i]) {
Expand All @@ -517,13 +517,15 @@ static int s_base64_encoding_test_roundtrip(struct aws_allocator *allocator, voi
fprintf(stderr, " %c", test_b64[i]);
}
fprintf(stderr, "\n");
memset(test_hex, 0, sizeof(test_hex));
aws_byte_buf_reset(&hex, true /*zero-contents*/);
struct aws_byte_cursor decoded_cur = aws_byte_cursor_from_buf(&decoded_buf);
aws_hex_encode(&decoded_cur, &hex);
fprintf(stderr, "Decoded : %s\n", (char *)test_hex);
fprintf(stderr, "Decoded : " PRInSTR "\n", AWS_BYTE_BUF_PRI(hex));
return 1;
}

aws_byte_buf_clean_up(&hex);
aws_byte_buf_clean_up(&decoded_buf);
return 0;
}
AWS_TEST_CASE(base64_encoding_test_roundtrip, s_base64_encoding_test_roundtrip)
Expand Down
1 change: 0 additions & 1 deletion tests/fuzz/hex_encoding_transitive.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {

result = aws_hex_encode(&to_encode, &encode_output);
AWS_ASSERT(result == AWS_OP_SUCCESS);
--encode_output.len; /* Remove null terminator */

result = aws_hex_compute_decoded_len(encode_output.len, &output_size);
AWS_ASSERT(result == AWS_OP_SUCCESS);
Expand Down

0 comments on commit f1676e8

Please sign in to comment.