From e77eb65a661d6d524cdbf64843022723f55769a9 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Tue, 24 Jan 2017 13:50:59 +0100 Subject: fuzz: Added IDNA encoding/decoding fuzzying units Signed-off-by: Nikos Mavrogiannopoulos --- .gitignore | 1 + devel/fuzz/Makefile | 9 ++++- devel/fuzz/gnutls_idna_parser.in/dns1 | 1 + devel/fuzz/gnutls_idna_parser.in/dns2 | 1 + devel/fuzz/gnutls_idna_parser.in/dns3 | 1 + devel/fuzz/gnutls_idna_parser.in/dns4 | 1 + devel/fuzz/gnutls_idna_parser_fuzzer.cc | 39 ++++++++++++++++++++++ devel/fuzz/gnutls_reverse_idna_parser.in/ace1 | 1 + devel/fuzz/gnutls_reverse_idna_parser.in/ace2 | 1 + devel/fuzz/gnutls_reverse_idna_parser.in/ace3 | 1 + devel/fuzz/gnutls_reverse_idna_parser_fuzzer.cc | 39 ++++++++++++++++++++++ devel/fuzz/main.c | 44 +++++++++++++++++++++++++ 12 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 devel/fuzz/gnutls_idna_parser.in/dns1 create mode 100644 devel/fuzz/gnutls_idna_parser.in/dns2 create mode 100644 devel/fuzz/gnutls_idna_parser.in/dns3 create mode 100644 devel/fuzz/gnutls_idna_parser.in/dns4 create mode 100644 devel/fuzz/gnutls_idna_parser_fuzzer.cc create mode 100644 devel/fuzz/gnutls_reverse_idna_parser.in/ace1 create mode 100644 devel/fuzz/gnutls_reverse_idna_parser.in/ace2 create mode 100644 devel/fuzz/gnutls_reverse_idna_parser.in/ace3 create mode 100644 devel/fuzz/gnutls_reverse_idna_parser_fuzzer.cc create mode 100644 devel/fuzz/main.c diff --git a/.gitignore b/.gitignore index 97a353b514..6ce7207157 100644 --- a/.gitignore +++ b/.gitignore @@ -205,6 +205,7 @@ doc/tpm-api.texi doc/version-guile.texi doc/version.texi doc/x509-api.texi +devel/fuzz/gnutls_*_fuzzer extra/Makefile extra/Makefile.in extra/includes/Makefile diff --git a/devel/fuzz/Makefile b/devel/fuzz/Makefile index fc9d95c55c..8e83dd12a8 100644 --- a/devel/fuzz/Makefile +++ b/devel/fuzz/Makefile @@ -48,7 +48,14 @@ gnutls_server_fuzzer: gnutls_server_fuzzer.cc gnutls_x509_parser_fuzzer: gnutls_x509_parser_fuzzer.cc $(CC) $(CFLAGS) main.c $^ $(COMMON) -o $@ +gnutls_idna_parser_fuzzer: gnutls_idna_parser_fuzzer.cc + $(CC) $(CFLAGS) main.c $^ $(COMMON) -o $@ + +gnutls_reverse_idna_parser_fuzzer: gnutls_reverse_idna_parser_fuzzer.cc + $(CC) $(CFLAGS) main.c $^ $(COMMON) -o $@ + clean: rm -f gnutls_pkcs7_parser_fuzzer gnutls_client_fuzzer gnutls_dn_parser_fuzzer \ gnutls_openpgp_cert_parser_fuzzer gnutls_pkcs7_parser_fuzzer gnutls_pkcs8_key_parser_fuzzer \ - gnutls_private_key_parser_fuzzer gnutls_server_fuzzer gnutls_x509_parser_fuzzer + gnutls_private_key_parser_fuzzer gnutls_server_fuzzer gnutls_x509_parser_fuzzer \ + gnutls_idna_parser_fuzzer gnutls_reverse_idna_parser_fuzzer diff --git a/devel/fuzz/gnutls_idna_parser.in/dns1 b/devel/fuzz/gnutls_idna_parser.in/dns1 new file mode 100644 index 0000000000..13ce7f21d1 --- /dev/null +++ b/devel/fuzz/gnutls_idna_parser.in/dns1 @@ -0,0 +1 @@ +LOCALHOST diff --git a/devel/fuzz/gnutls_idna_parser.in/dns2 b/devel/fuzz/gnutls_idna_parser.in/dns2 new file mode 100644 index 0000000000..7fed584a6e --- /dev/null +++ b/devel/fuzz/gnutls_idna_parser.in/dns2 @@ -0,0 +1 @@ +bücher.de diff --git a/devel/fuzz/gnutls_idna_parser.in/dns3 b/devel/fuzz/gnutls_idna_parser.in/dns3 new file mode 100644 index 0000000000..30babe3601 --- /dev/null +++ b/devel/fuzz/gnutls_idna_parser.in/dns3 @@ -0,0 +1 @@ +日本語.jp diff --git a/devel/fuzz/gnutls_idna_parser.in/dns4 b/devel/fuzz/gnutls_idna_parser.in/dns4 new file mode 100644 index 0000000000..c08920141f --- /dev/null +++ b/devel/fuzz/gnutls_idna_parser.in/dns4 @@ -0,0 +1 @@ +简体中文.εξτρα.com diff --git a/devel/fuzz/gnutls_idna_parser_fuzzer.cc b/devel/fuzz/gnutls_idna_parser_fuzzer.cc new file mode 100644 index 0000000000..06e89b8a36 --- /dev/null +++ b/devel/fuzz/gnutls_idna_parser_fuzzer.cc @@ -0,0 +1,39 @@ +/* +# Copyright 2016 Nikos Mavrogiannopoulos +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +*/ + +#include +#include +#include + +#include + + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + gnutls_datum_t out; + int ret; + + ret = gnutls_idna_map((const char*)data, size, &out, 0); + if (ret < 0) + goto cleanup; + + printf("%s\n", (char*)out.data); + gnutls_free(out.data); + + cleanup: + return 0; +} diff --git a/devel/fuzz/gnutls_reverse_idna_parser.in/ace1 b/devel/fuzz/gnutls_reverse_idna_parser.in/ace1 new file mode 100644 index 0000000000..64b6119730 --- /dev/null +++ b/devel/fuzz/gnutls_reverse_idna_parser.in/ace1 @@ -0,0 +1 @@ +xn--fa-hia.de diff --git a/devel/fuzz/gnutls_reverse_idna_parser.in/ace2 b/devel/fuzz/gnutls_reverse_idna_parser.in/ace2 new file mode 100644 index 0000000000..a42c184210 --- /dev/null +++ b/devel/fuzz/gnutls_reverse_idna_parser.in/ace2 @@ -0,0 +1 @@ +xn--fiqu1az03c18t.xn--mxah1amo.com diff --git a/devel/fuzz/gnutls_reverse_idna_parser.in/ace3 b/devel/fuzz/gnutls_reverse_idna_parser.in/ace3 new file mode 100644 index 0000000000..13ce7f21d1 --- /dev/null +++ b/devel/fuzz/gnutls_reverse_idna_parser.in/ace3 @@ -0,0 +1 @@ +LOCALHOST diff --git a/devel/fuzz/gnutls_reverse_idna_parser_fuzzer.cc b/devel/fuzz/gnutls_reverse_idna_parser_fuzzer.cc new file mode 100644 index 0000000000..1b0a398e02 --- /dev/null +++ b/devel/fuzz/gnutls_reverse_idna_parser_fuzzer.cc @@ -0,0 +1,39 @@ +/* +# Copyright 2016 Nikos Mavrogiannopoulos +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +*/ + +#include +#include +#include + +#include + + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + gnutls_datum_t out; + int ret; + + ret = gnutls_idna_reverse_map((char*)data, size, &out, 0); + if (ret < 0) + goto cleanup; + + printf("%s\n", (char*)out.data); + gnutls_free(out.data); + + cleanup: + return 0; +} diff --git a/devel/fuzz/main.c b/devel/fuzz/main.c new file mode 100644 index 0000000000..602943014c --- /dev/null +++ b/devel/fuzz/main.c @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2017 Nikos Mavrogiannopoulos + * + * Author: Nikos Mavrogiannopoulos + * + * This file is part of GnuTLS. + * + * The GnuTLS is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); + +int main(int argc, char **argv) +{ + int ret; + unsigned char buf[64*1024]; + + ret = fread(buf, 1, sizeof(buf), stdin); + if (ret <= 0) + return 0; + + return LLVMFuzzerTestOneInput(buf, ret); +} -- cgit v1.2.1