diff options
author | Pauli <pauli@openssl.org> | 2022-11-03 22:43:38 +0100 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2022-11-10 22:14:48 +0100 |
commit | 8aa82b337081b7a22c35dddad8d62fb1ca9ea884 (patch) | |
tree | e9dc998fcb32f605bc83a552f587e62fa78ceee2 /fuzz | |
parent | punycode: update to use WPACKET instead of using custom range checking (diff) | |
download | openssl-8aa82b337081b7a22c35dddad8d62fb1ca9ea884.tar.xz openssl-8aa82b337081b7a22c35dddad8d62fb1ca9ea884.zip |
fuzz: add punycode decoder fuzz test
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/19591)
Diffstat (limited to 'fuzz')
-rw-r--r-- | fuzz/build.info | 10 | ||||
-rw-r--r-- | fuzz/corpora/punycode/0000000000000000000000000000000000000000 | bin | 0 -> 132 bytes | |||
-rw-r--r-- | fuzz/corpora/punycode/0000000000000000000000000000000000000001 | bin | 0 -> 18 bytes | |||
-rw-r--r-- | fuzz/fuzzer.h | 3 | ||||
-rw-r--r-- | fuzz/punycode.c | 42 |
5 files changed, 55 insertions, 0 deletions
diff --git a/fuzz/build.info b/fuzz/build.info index 7b26b8c152..7ba41a7a6e 100644 --- a/fuzz/build.info +++ b/fuzz/build.info @@ -10,6 +10,7 @@ IF[{- !$disabled{"fuzz-afl"} || !$disabled{"fuzz-libfuzzer"} -}] PROGRAMS{noinst}=asn1 asn1parse bignum bndiv client conf crl server x509 + PROGRAMS{noinst}=punycode IF[{- !$disabled{"cmp"} -}] PROGRAMS{noinst}=cmp @@ -63,6 +64,10 @@ IF[{- !$disabled{"fuzz-afl"} || !$disabled{"fuzz-libfuzzer"} -}] INCLUDE[ct]=../include {- $ex_inc -} DEPEND[ct]=../libcrypto {- $ex_lib -} + SOURCE[punycode]=punycode.c driver.c + INCLUDE[punycode]=../include {- $ex_inc -} + DEPEND[punycode]=../libcrypto.a {- $ex_lib -} + SOURCE[server]=server.c driver.c fuzz_rand.c INCLUDE[server]=../include {- $ex_inc -} DEPEND[server]=../libcrypto ../libssl {- $ex_lib -} @@ -74,6 +79,7 @@ ENDIF IF[{- !$disabled{tests} -}] PROGRAMS{noinst}=asn1-test asn1parse-test bignum-test bndiv-test client-test conf-test crl-test server-test x509-test + PROGRAMS{noinst}=punycode-test IF[{- !$disabled{"cmp"} -}] PROGRAMS{noinst}=cmp-test @@ -128,6 +134,10 @@ IF[{- !$disabled{tests} -}] INCLUDE[ct-test]=../include DEPEND[ct-test]=../libcrypto + SOURCE[punycode-test]=punycode.c test-corpus.c + INCLUDE[punycode-test]=../include + DEPEND[punycode-test]=../libcrypto.a + SOURCE[server-test]=server.c test-corpus.c fuzz_rand.c INCLUDE[server-test]=../include DEPEND[server-test]=../libcrypto ../libssl diff --git a/fuzz/corpora/punycode/0000000000000000000000000000000000000000 b/fuzz/corpora/punycode/0000000000000000000000000000000000000000 Binary files differnew file mode 100644 index 0000000000..36f7661734 --- /dev/null +++ b/fuzz/corpora/punycode/0000000000000000000000000000000000000000 diff --git a/fuzz/corpora/punycode/0000000000000000000000000000000000000001 b/fuzz/corpora/punycode/0000000000000000000000000000000000000001 Binary files differnew file mode 100644 index 0000000000..33abaeb3aa --- /dev/null +++ b/fuzz/corpora/punycode/0000000000000000000000000000000000000001 diff --git a/fuzz/fuzzer.h b/fuzz/fuzzer.h index cd460dea8d..4d8b7b9a51 100644 --- a/fuzz/fuzzer.h +++ b/fuzz/fuzzer.h @@ -8,6 +8,9 @@ * or in the file LICENSE in the source distribution. */ +#include <stdint.h> /* for uint8_t */ +#include <stddef.h> /* for size_t */ + int FuzzerTestOneInput(const uint8_t *buf, size_t len); int FuzzerInitialize(int *argc, char ***argv); void FuzzerCleanup(void); diff --git a/fuzz/punycode.c b/fuzz/punycode.c new file mode 100644 index 0000000000..76ae3dea0e --- /dev/null +++ b/fuzz/punycode.c @@ -0,0 +1,42 @@ +/* + * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include "crypto/punycode.h" +#include "internal/nelem.h" +#include <openssl/crypto.h> +#include "fuzzer.h" + +#include <stdio.h> +#include <string.h> + +int FuzzerInitialize(int *argc, char ***argv) +{ + return 1; +} + +int FuzzerTestOneInput(const uint8_t *buf, size_t len) +{ + char *b; + unsigned int out[16], outlen = OSSL_NELEM(out); + char outc[16]; + + b = OPENSSL_malloc(len + 1); + if (b != NULL) { + ossl_punycode_decode((const char *)buf, len, out, &outlen); + memcpy(b, buf, len); + b[len] = '\0'; + ossl_a2ulabel(b, outc, sizeof(outc)); + OPENSSL_free(b); + } + return 0; +} + +void FuzzerCleanup(void) +{ +} |