]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
tests: Added check for memory leaks when a file cannot be loaded.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 25 Nov 2014 20:53:03 +0000 (21:53 +0100)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 25 Nov 2014 20:53:09 +0000 (21:53 +0100)
tests/Makefile.am
tests/set_x509_key_file.c [new file with mode: 0644]

index 6d308c5219043328c71604e7c35713a286c4ff1c..cc6a1e82637fd09b1c6f8c18189ee4b3d08bb2a4 100644 (file)
@@ -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 (file)
index 0000000..8e1cf9d
--- /dev/null
@@ -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 <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
+
+#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();
+}