From: Nikos Mavrogiannopoulos Date: Tue, 25 Nov 2014 20:53:03 +0000 (+0100) Subject: tests: Added check for memory leaks when a file cannot be loaded. X-Git-Tag: gnutls_3_4_0~556 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ed3913fdbc8ffe3b552c0d0f593f17c4e1a273d5;p=thirdparty%2Fgnutls.git tests: Added check for memory leaks when a file cannot be loaded. --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 6d308c5219..cc6a1e8263 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -85,7 +85,7 @@ ctests = mini-record-2 simple gc set_pkcs12_cred certder certuniqueid \ fips-test mini-global-load name-constraints x509-extensions \ long-session-id mini-x509-callbacks-intr mini-dtls-lowmtu \ crlverify mini-dtls-discard init_fds mini-record-failure \ - mini-rehandshake-2 custom-urls set_x509_key_mem + mini-rehandshake-2 custom-urls set_x509_key_mem set_x509_key_file if ENABLE_OCSP ctests += ocsp diff --git a/tests/set_x509_key_file.c b/tests/set_x509_key_file.c new file mode 100644 index 0000000000..8e1cf9d859 --- /dev/null +++ b/tests/set_x509_key_file.c @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2014 Nikos Mavrogiannopoulos + * + * Author: Nikos Mavrogiannopoulos + * + * This file is part of GnuTLS. + * + * GnuTLS is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * GnuTLS is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GnuTLS; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include + +#include "utils.h" + +void doit(void) +{ + int ret; + gnutls_certificate_credentials_t xcred; + const char *keyfile = "./certs/ecc256.pem"; + const char *certfile = "does-not-exist.pem"; + + global_init(); + ret = gnutls_certificate_allocate_credentials(&xcred); + + /* this will fail */ + ret = gnutls_certificate_set_x509_key_file(xcred, certfile, keyfile, + GNUTLS_X509_FMT_PEM); + if (ret != GNUTLS_E_FILE_ERROR) + fail("set_x509_key_file failed: %s\n", gnutls_strerror(ret)); + + gnutls_certificate_free_credentials(xcred); + gnutls_global_deinit(); +}