Skip to content

fuzz-tests: Improve the fuzz-base32-64 test #8183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions common/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ char *b64_encode(const tal_t *ctx, const void *data, size_t len)
str[enclen] = '\0';
return str;
}

u8 *b64_decode(const tal_t *ctx, const char *str, size_t len)
{
size_t dlen = base64_decoded_length(len);
u8 *ret = tal_arr(ctx, u8, dlen);
if (base64_decode((char *)ret, dlen, str, len) < 0)
return tal_free(ret);
return ret;
}
1 change: 1 addition & 0 deletions common/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
#include <ccan/tal/tal.h>

char *b64_encode(const tal_t *ctx, const void *data, size_t len);
u8 *b64_decode(const tal_t *ctx, const char *str, size_t len);

#endif /* LIGHTNING_COMMON_BASE64_H */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
??
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�����������������������������������*�����������������������������*�������������������������������������������������������������������������������������������������������������������
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
H��w��w�����
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vvvvvvvvvvvvvvvvvvvvvvvA
Binary file not shown.
3 changes: 3 additions & 0 deletions tests/fuzz/fuzz-base32-64.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ void run(const uint8_t *data, size_t size)
tal_free(decoded);

encoded = b64_encode(NULL, data, size);
decoded = b64_decode(NULL, encoded, strlen(encoded));
assert(memcmp(decoded, data, size) == 0);
tal_free(encoded);
tal_free(decoded);
}