Coverage Report

Created: 2026-09-01 06:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mod_auth_openidc/test/fuzz/fuzz.h
Line
Count
Source
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  Licensed under the Apache License,
4
 * Version 2.0 (the "License"); you may not use this file except in
5
 * compliance with the License.  You may obtain a copy of the License at
6
 *
7
 *   http://www.apache.org/licenses/LICENSE-2.0
8
 *
9
 * Copyright (C) 2017-2026 ZmartZone Holding BV - hans.zandbelt@openidc.com
10
 *
11
 * fuzz.h -- shared declarations for the fuzz targets under test/fuzz/.
12
 *
13
 * Each target implements the libFuzzer entry point below. The same object
14
 * builds two ways:
15
 *   - linked with standalone.c + plain cc  -> a corpus-replay binary run by
16
 *     test/fuzz/run-fuzzers.sh as part of `make check` (regression guard);
17
 *   - compiled with `clang -fsanitize=fuzzer` -> a real libFuzzer binary
18
 *     (libFuzzer provides main); see test/fuzz/build.sh.
19
 */
20
21
#ifndef _MOD_AUTH_OPENIDC_TEST_FUZZ_H_
22
#define _MOD_AUTH_OPENIDC_TEST_FUZZ_H_
23
24
#include <apr_pools.h>
25
#include <stddef.h>
26
#include <stdint.h>
27
#include <string.h>
28
29
/* the one entry point every fuzz target implements */
30
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
31
32
/*
33
 * Copy the fuzzer's input bytes into a NUL-terminated string on the given pool.
34
 *
35
 * Deliberately not apr_pstrmemdup(): APR declares that function with
36
 * __attribute__((alloc_size(3))), which tells the compiler the result is n
37
 * bytes long although APR allocates n + 1 -- so under gcc's UBSan object-size
38
 * check (the CI sanitizers job builds the targets with -fsanitize=undefined
39
 * -fno-sanitize-recover) a harness that reads the terminator, or [0] of an
40
 * empty input, is reported as an out-of-object load and the replay aborts.
41
 * apr_palloc's own size annotation is truthful, so this copy is not.
42
 */
43
31.1k
static inline char *fuzz_strndup(apr_pool_t *pool, const uint8_t *data, size_t size) {
44
31.1k
  char *s = apr_palloc(pool, size + 1);
45
31.1k
  if (size > 0)
46
31.0k
    memcpy(s, data, size);
47
31.1k
  s[size] = '\0';
48
31.1k
  return s;
49
31.1k
}
Unexecuted instantiation: fuzz_response_header.c:fuzz_strndup
Unexecuted instantiation: fuzz_json.c:fuzz_strndup
Unexecuted instantiation: fuzz_state_cookie.c:fuzz_strndup
fuzz_bearer_token.c:fuzz_strndup
Line
Count
Source
43
7.56k
static inline char *fuzz_strndup(apr_pool_t *pool, const uint8_t *data, size_t size) {
44
7.56k
  char *s = apr_palloc(pool, size + 1);
45
7.56k
  if (size > 0)
46
7.54k
    memcpy(s, data, size);
47
7.56k
  s[size] = '\0';
48
7.56k
  return s;
49
7.56k
}
fuzz_redirect_uri.c:fuzz_strndup
Line
Count
Source
43
4.60k
static inline char *fuzz_strndup(apr_pool_t *pool, const uint8_t *data, size_t size) {
44
4.60k
  char *s = apr_palloc(pool, size + 1);
45
4.60k
  if (size > 0)
46
4.58k
    memcpy(s, data, size);
47
4.60k
  s[size] = '\0';
48
4.60k
  return s;
49
4.60k
}
fuzz_backchannel_logout.c:fuzz_strndup
Line
Count
Source
43
7.50k
static inline char *fuzz_strndup(apr_pool_t *pool, const uint8_t *data, size_t size) {
44
7.50k
  char *s = apr_palloc(pool, size + 1);
45
7.50k
  if (size > 0)
46
7.50k
    memcpy(s, data, size);
47
7.50k
  s[size] = '\0';
48
7.50k
  return s;
49
7.50k
}
Unexecuted instantiation: fuzz_discovery_response.c:fuzz_strndup
fuzz_authz_response.c:fuzz_strndup
Line
Count
Source
43
6.83k
static inline char *fuzz_strndup(apr_pool_t *pool, const uint8_t *data, size_t size) {
44
6.83k
  char *s = apr_palloc(pool, size + 1);
45
6.83k
  if (size > 0)
46
6.80k
    memcpy(s, data, size);
47
6.83k
  s[size] = '\0';
48
6.83k
  return s;
49
6.83k
}
Unexecuted instantiation: fuzz_jwt.c:fuzz_strndup
Unexecuted instantiation: fuzz_cookie.c:fuzz_strndup
fuzz_post_preserve.c:fuzz_strndup
Line
Count
Source
43
780
static inline char *fuzz_strndup(apr_pool_t *pool, const uint8_t *data, size_t size) {
44
780
  char *s = apr_palloc(pool, size + 1);
45
780
  if (size > 0)
46
780
    memcpy(s, data, size);
47
780
  s[size] = '\0';
48
780
  return s;
49
780
}
Unexecuted instantiation: fuzz_pem_key.c:fuzz_strndup
Unexecuted instantiation: fuzz_metadata.c:fuzz_strndup
fuzz_strings.c:fuzz_strndup
Line
Count
Source
43
3.45k
static inline char *fuzz_strndup(apr_pool_t *pool, const uint8_t *data, size_t size) {
44
3.45k
  char *s = apr_palloc(pool, size + 1);
45
3.45k
  if (size > 0)
46
3.45k
    memcpy(s, data, size);
47
3.45k
  s[size] = '\0';
48
3.45k
  return s;
49
3.45k
}
Unexecuted instantiation: fuzz_jwks.c:fuzz_strndup
fuzz_current_url.c:fuzz_strndup
Line
Count
Source
43
381
static inline char *fuzz_strndup(apr_pool_t *pool, const uint8_t *data, size_t size) {
44
381
  char *s = apr_palloc(pool, size + 1);
45
381
  if (size > 0)
46
381
    memcpy(s, data, size);
47
381
  s[size] = '\0';
48
381
  return s;
49
381
}
Unexecuted instantiation: fuzz_url.c:fuzz_strndup
Unexecuted instantiation: fuzz_base64.c:fuzz_strndup
Unexecuted instantiation: fuzz_form_params.c:fuzz_strndup
50
51
/*
52
 * One-time fixture setup (oidc_test_setup), implemented by every target.
53
 * libFuzzer and honggfuzz call this once at startup; AFL++'s driver calls it
54
 * *before* spawning its deferred forkserver, and that ordering is the point:
55
 * the full post-config fixture init must run once in the forkserver parent,
56
 * not inside every forked child's first LLVMFuzzerTestOneInput call, where
57
 * afl-fuzz's per-exec timeout (5s in the OSS-Fuzz build check) counts it.
58
 * afl-fuzz also injects LSAN_OPTIONS containing fast_unwind_on_malloc=0 into
59
 * the target environment, which makes ASan DWARF-unwind every allocation the
60
 * init makes and inflates that first exec from ~0.2s to seconds -- the cause
61
 * of the "All test cases time out" OSS-Fuzz build-check failures on the afl
62
 * engine. Targets keep a lazy fallback in LLVMFuzzerTestOneInput for runners
63
 * that do not call this (the standalone corpus-replay main).
64
 */
65
int LLVMFuzzerInitialize(int *argc, char ***argv);
66
67
#endif /* _MOD_AUTH_OPENIDC_TEST_FUZZ_H_ */