]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
tests: added reproducer for server issues
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Wed, 4 Jan 2017 08:42:25 +0000 (09:42 +0100)
committerNikos Mavrogiannopoulos <nmav@redhat.com>
Wed, 4 Jan 2017 12:41:48 +0000 (13:41 +0100)
This allows to reproduce issues found on server side, by adding
a transcript in server-interesting. Currently it contains values
found using oss-fuzz.

Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
devel/fuzz/README.md
devel/fuzz/gnutls_server_fuzzer.cc
tests/Makefile.am
tests/server-interesting/server1.raw [new file with mode: 0644]
tests/server.c [new file with mode: 0644]

index 5471255e717e5e087578b099b43c97657591fa35..476fca09da3dcd444cf14cc232d696d317fef013 100644 (file)
@@ -37,6 +37,7 @@ sufficient:
 
 |---------------------------|-------------------------|
 |gnutls_client_fuzzer       | tests/client-interesting|
+|gnutls_server_fuzzer       | tests/server-interesting|
 |gnutls_pkcs7_parser_fuzzer | tests/pkcs7-interesting |
 |gnutls_x509_parser_fuzzer  | tests/certs-interesting |
 |---------------------------|-------------------------|
@@ -49,5 +50,4 @@ table below.
 |gnutls_openpgp_cert_parser_fuzzer|tests/cert-tests/openpgp-cert-parser                      |
 |gnutls_pkcs8_key_parser_fuzzer   |tests/key-tests/pkcs8-invalid,tests/key-tests/pkcs8-decode|
 |gnutls_private_key_parser_fuzzer |tests/key-tests/key-invalid                               |
-|gnutls_server_fuzzer             |none atm (should duplicate the client fuzzer)             |
 |---------------------------------|----------------------------------------------------------|
index e864f103540a56e9e2067feff9565b6a410506d5..1d1f87d1959f2673c51a149c5de10d0c260ad78e 100644 (file)
@@ -194,7 +194,11 @@ static const uint8_t kRSAPrivateKeyDER[] = {
     0x98, 0x46, 0x89, 0x82, 0x40,
 };
 
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+#ifdef __cplusplus
+extern "C"
+#endif
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
+{
     int res;
     gnutls_datum_t cert, key;
     gnutls_session_t session;
index f34e5994cbc9694da2c90a3f97296b655d2b81a6..d0ce446390dacdf548da1153c47d00b16a2954bc 100644 (file)
@@ -39,7 +39,8 @@ EXTRA_DIST = suppressions.valgrind eagain-common.h cert-common.h test-chains.h \
        certs-interesting/cert6.der certs-interesting/cert7.der certs-interesting/cert8.der \
        certs-interesting/cert3.der.err certs-interesting/cert4.der pkcs7-interesting/pkcs7-1.der \
        pkcs7-interesting/pkcs7-1.der.err pkcs7-interesting/pkcs7-2.der pkcs7-interesting/pkcs7-2.der.err \
-       client-interesting/client1.raw client-interesting/client2.raw client-interesting/client3.disabled
+       client-interesting/client1.raw client-interesting/client2.raw client-interesting/client3.disabled \
+       server-interesting/server1.raw
 
 AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
 AM_CPPFLAGS = \
@@ -324,7 +325,8 @@ TESTS_ENVIRONMENT =                                         \
 
 if WANT_TEST_SUITE
 
-ctests += client
+# These require the devel/fuzz directory which is not available on releases
+ctests += client server
 
 LOG_COMPILER = $(VALGRIND)
 endif
diff --git a/tests/server-interesting/server1.raw b/tests/server-interesting/server1.raw
new file mode 100644 (file)
index 0000000..4149fc4
Binary files /dev/null and b/tests/server-interesting/server1.raw differ
diff --git a/tests/server.c b/tests/server.c
new file mode 100644 (file)
index 0000000..4067bb8
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2016 Red Hat, Inc.
+ * Copyright 2016 Alex Gaynor, Google Inc.
+ *
+ * Author: Nikos Mavrogiannopoulos, Alex Gaynor
+ *
+ * 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 <gnutls/gnutls.h>
+#include <gnutls/x509.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <limits.h>
+#include <dirent.h>
+
+#include "utils.h"
+
+#define true 1
+
+/* This program will load certificates from CERT_DIR and try to print
+ * them. If CERT_DIR/certname.err is available, it should contain the
+ * error code that gnutls_x509_crt_import() should return.
+ */
+
+#define CERT_DIR "server-interesting"
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
+
+static int getnext(DIR **dirp, gnutls_datum_t *der)
+{
+       struct dirent *d;
+       char path[256];
+       char cert_dir[256];
+       const char *src;
+       int ret;
+
+       src = getenv("srcdir");
+       if (src == NULL)
+               src = ".";
+
+       snprintf(cert_dir, sizeof(cert_dir), "%s/%s", src, CERT_DIR);
+
+       if (*dirp == NULL) {
+               *dirp = opendir(cert_dir);
+               if (*dirp == NULL)
+                       return -1;
+       }
+
+       do {
+               d = readdir(*dirp);
+               if (d != NULL
+#ifdef _DIRENT_HAVE_D_TYPE
+                       && d->d_type == DT_REG
+#endif
+                       ) {
+                       if (strstr(d->d_name, ".raw") == 0)
+                               continue;
+                       snprintf(path, sizeof(path), "%s/%s", cert_dir, d->d_name);
+
+                       success("Loading %s\n", path);
+                       ret = gnutls_load_file(path, der);
+                       if (ret < 0) {
+                               return -1;
+                       }
+
+                       return 0;
+               }
+       } while(d != NULL);
+
+       closedir(*dirp);
+       return -1; /* finished */
+}
+
+#include "../devel/fuzz/gnutls_server_fuzzer.cc"
+
+void doit(void)
+{
+       int ret;
+       gnutls_datum_t raw;
+       DIR *dirp = NULL;
+
+       ret = global_init();
+       if (ret < 0)
+               fail("init %d\n", ret);
+
+       while (getnext(&dirp, &raw)==0) {
+               LLVMFuzzerTestOneInput(raw.data, raw.size);
+               gnutls_free(raw.data);
+               raw.data = NULL;
+               raw.size = 0;
+       }
+
+       gnutls_global_deinit();
+}