diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2017-04-21 09:14:18 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2017-04-21 09:14:33 +0200 |
commit | f0eda7c42ba1c9c3d62ddd80a200b3f2bc5ec7f3 (patch) | |
tree | e98ecdb6cf781da701e7f676629362d09e21b4dd | |
parent | c3cfbb3d7b1cc7233e292aa1a3f1af0316707713 (diff) | |
download | gnutls-f0eda7c42ba1c9c3d62ddd80a200b3f2bc5ec7f3.tar.gz |
tests: check whether gnutls_pem_base64_decode2 decodes with null argument
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
-rw-r--r-- | tests/base64.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/base64.c b/tests/base64.c index 65af597068..9c89cb3ad0 100644 --- a/tests/base64.c +++ b/tests/base64.c @@ -112,6 +112,34 @@ static void decode(const char *test_name, const gnutls_datum_t *raw, const char gnutls_free(out.data); + /* decode with null argument */ + in.data = (void*)hex; + in.size = strlen(hex); + ret = gnutls_pem_base64_decode2(NULL, &in, &out); + if (ret < 0) { + if (res == ret) /* expected */ + return; + fail("%s: gnutls_pem_base64_decode2: %d/%s\n", test_name, ret, gnutls_strerror(ret)); + exit(1); + } + + if (res != 0) { + fail("%s: gnutls_pem_base64_decode2: expected failure, but succeeded!\n", test_name); + exit(1); + } + + if (raw->size!=out.size) { + fail("%s: gnutls_pem_base64_decode2: output has incorrect size (%d, expected %d)\n", test_name, out.size, raw->size); + exit(1); + } + + if (memcmp(raw->data, out.data, out.size) != 0) { + fail("%s: gnutls_pem_base64_decode2: output does not match the expected\n", test_name); + exit(1); + } + + gnutls_free(out.data); + return; } |