mirror of
https://github.com/openssl/openssl.git
synced 2025-01-18 13:44:20 +08:00
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)
This commit is contained in:
parent
905ba92439
commit
8aa82b3370
@ -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
|
||||
|
BIN
fuzz/corpora/punycode/0000000000000000000000000000000000000000
Normal file
BIN
fuzz/corpora/punycode/0000000000000000000000000000000000000000
Normal file
Binary file not shown.
BIN
fuzz/corpora/punycode/0000000000000000000000000000000000000001
Normal file
BIN
fuzz/corpora/punycode/0000000000000000000000000000000000000001
Normal file
Binary file not shown.
@ -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);
|
||||
|
42
fuzz/punycode.c
Normal file
42
fuzz/punycode.c
Normal file
@ -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)
|
||||
{
|
||||
}
|
@ -11,6 +11,8 @@
|
||||
# define OSSL_CRYPTO_PUNYCODE_H
|
||||
# pragma once
|
||||
|
||||
# include <stddef.h> /* for size_t */
|
||||
|
||||
int ossl_punycode_decode (
|
||||
const char *pEncoded,
|
||||
const size_t enc_len,
|
||||
|
Loading…
Reference in New Issue
Block a user