diff options
Diffstat (limited to 'contrib/libfido2/fuzz/wrap.c')
-rw-r--r-- | contrib/libfido2/fuzz/wrap.c | 67 |
1 files changed, 65 insertions, 2 deletions
diff --git a/contrib/libfido2/fuzz/wrap.c b/contrib/libfido2/fuzz/wrap.c index 8d7be6bb6247..6f40ea1d079e 100644 --- a/contrib/libfido2/fuzz/wrap.c +++ b/contrib/libfido2/fuzz/wrap.c @@ -1,10 +1,12 @@ /* - * Copyright (c) 2019-2021 Yubico AB. All rights reserved. + * Copyright (c) 2019-2022 Yubico AB. All rights reserved. * Use of this source code is governed by a BSD-style * license that can be found in the LICENSE file. + * SPDX-License-Identifier: BSD-2-Clause */ #include <sys/types.h> +#include <sys/random.h> #include <sys/socket.h> #include <openssl/bn.h> @@ -16,14 +18,19 @@ #include <stdint.h> #include <stdio.h> #include <stdlib.h> +#include <zlib.h> #include "mutator_aux.h" extern int prng_up; +int fuzz_save_corpus; + /* * Build wrappers around functions of interest, and have them fail - * in a pseudo-random manner. + * in a pseudo-random manner. A uniform probability of 0.25% (1/400) + * allows for a depth of log(0.5)/log(399/400) > 276 operations + * before simulated errors become statistically more likely. */ #define WRAP(type, name, args, retval, param, prob) \ @@ -69,6 +76,14 @@ WRAP(char *, 1 ) +WRAP(ssize_t, + getrandom, + (void *buf, size_t buflen, unsigned int flags), + -1, + (buf, buflen, flags), + 1 +) + WRAP(int, EVP_Cipher, (EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, @@ -635,3 +650,51 @@ WRAP(int, (sockfd, addr, addrlen), 1 ) + +WRAP(int, + deflateInit2_, + (z_streamp strm, int level, int method, int windowBits, int memLevel, + int strategy, const char *version, int stream_size), + Z_STREAM_ERROR, + (strm, level, method, windowBits, memLevel, strategy, version, + stream_size), + 1 +) + +int __wrap_deflate(z_streamp, int); +int __real_deflate(z_streamp, int); + +int +__wrap_deflate(z_streamp strm, int flush) +{ + if (prng_up && uniform_random(400) < 1) { + return Z_BUF_ERROR; + } + /* should never happen, but we check for it */ + if (prng_up && uniform_random(400) < 1) { + strm->avail_out = UINT_MAX; + return Z_STREAM_END; + } + + return __real_deflate(strm, flush); +} + +int __wrap_asprintf(char **, const char *, ...); + +int +__wrap_asprintf(char **strp, const char *fmt, ...) +{ + va_list ap; + int r; + + if (prng_up && uniform_random(400) < 1) { + *strp = (void *)0xdeadbeef; + return -1; + } + + va_start(ap, fmt); + r = vasprintf(strp, fmt, ap); + va_end(ap); + + return r; +} |