diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-01-10 12:39:14 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-01-16 16:19:07 +0100 |
commit | 5040b2cfab1f3d778b6d253b5c5c5f50980f6535 (patch) | |
tree | 7dd5e0f00886d72b20a438fb59f567bf812d0136 /src/test/test-hexdecoct.c | |
parent | tree-wide: use CLEANUP_ERASE() at various places (diff) | |
download | systemd-5040b2cfab1f3d778b6d253b5c5c5f50980f6535.tar.xz systemd-5040b2cfab1f3d778b6d253b5c5c5f50980f6535.zip |
memory-util: add CLEANUP_ERASE_PTR() macro and use it
Diffstat (limited to '')
-rw-r--r-- | src/test/test-hexdecoct.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/test/test-hexdecoct.c b/src/test/test-hexdecoct.c index afdc3b5436..9d71db6ae1 100644 --- a/src/test/test-hexdecoct.c +++ b/src/test/test-hexdecoct.c @@ -322,6 +322,13 @@ TEST(base64mem_linebreak) { assert_se(decoded_size == n); assert_se(memcmp(data, decoded, n) == 0); + /* Also try in secure mode */ + decoded = mfree(decoded); + decoded_size = 0; + assert_se(unbase64mem_full(encoded, SIZE_MAX, /* secure= */ true, &decoded, &decoded_size) >= 0); + assert_se(decoded_size == n); + assert_se(memcmp(data, decoded, n) == 0); + for (size_t j = 0; j < (size_t) l; j++) assert_se((encoded[j] == '\n') == (j % (m + 1) == m)); } @@ -446,7 +453,17 @@ static void test_unbase64mem_one(const char *input, const char *output, int ret) size_t size = 0; assert_se(unbase64mem(input, SIZE_MAX, &buffer, &size) == ret); + if (ret >= 0) { + assert_se(size == strlen(output)); + assert_se(memcmp(buffer, output, size) == 0); + assert_se(((char*) buffer)[size] == 0); + } + + /* also try in secure mode */ + buffer = mfree(buffer); + size = 0; + assert_se(unbase64mem_full(input, SIZE_MAX, /* secure=*/ true, &buffer, &size) == ret); if (ret >= 0) { assert_se(size == strlen(output)); assert_se(memcmp(buffer, output, size) == 0); |