Coverage Report

Created: 2026-08-31 07:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mod_auth_openidc/test/fuzz/fuzz_metadata.c
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 target for the metadata parsers: a provider metadata document is
12
 * remote-attacker-influenced input (OP discovery responses, possibly via
13
 * user-supplied discovery in multi-provider setups), and the client/conf
14
 * documents share the same typed field extraction. The decoded JSON is fed
15
 * to oidc_metadata_provider_is_valid() and then to the three parsers in the
16
 * order oidc_metadata_get() applies them, so the same document stresses the
17
 * provider, conf and client key sets plus the url/array/boolean validators
18
 * they share (metadata/util.c, cfg/provider.c setters).
19
 */
20
21
#include "fuzz.h"
22
/* util.h pulls in const.h before any Apache header does, so config.h's
23
 * PACKAGE_* defines win the race against Apache's own (empty) ones in
24
 * ap_config_auto.h -- json.h includes httpd.h directly; keep util.h ahead
25
 * of it, see cfg/cfg.h's own ordering (clang-format's include sorting
26
 * would undo exactly that, hence the guard) */
27
/* clang-format off */
28
#include "util.h"      /* test fixture */
29
#include "json.h"
30
#include "metadata.h"
31
#include "util/util.h" /* oidc_json_decode_object */
32
/* clang-format on */
33
34
#include <apr_pools.h>
35
#include <apr_strings.h>
36
37
static int g_ready = 0;
38
39
/* engine-called one-time init, pre-forkserver on AFL++: see fuzz.h */
40
34
int LLVMFuzzerInitialize(int *argc, char ***argv) {
41
34
  (void)argc;
42
34
  (void)argv;
43
34
  if (!g_ready) {
44
34
    oidc_test_setup();
45
34
    g_ready = 1;
46
34
  }
47
34
  return 0;
48
34
}
49
50
9.03k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
51
9.03k
  if (!g_ready)
52
0
    LLVMFuzzerInitialize(NULL, NULL);
53
54
9.03k
  apr_pool_t *pool = NULL;
55
9.03k
  apr_pool_create(&pool, oidc_test_pool_get());
56
57
9.03k
  request_rec r = *oidc_test_request_get();
58
9.03k
  r.pool = pool;
59
9.03k
  oidc_cfg_t *cfg = oidc_test_cfg_get();
60
61
9.03k
  char *s = apr_pstrmemdup(pool, (const char *)data, size);
62
9.03k
  oidc_json_t *json = NULL;
63
9.03k
  if ((oidc_json_decode_object(&r, s, &json) == TRUE) && (json != NULL)) {
64
5.08k
    oidc_provider_t *provider = oidc_cfg_provider_create(pool);
65
5.08k
    oidc_metadata_provider_is_valid(&r, cfg, json, NULL);
66
5.08k
    oidc_metadata_provider_parse(&r, cfg, json, provider);
67
5.08k
    oidc_metadata_conf_parse(&r, cfg, json, provider);
68
5.08k
    oidc_metadata_client_parse(&r, cfg, json, provider);
69
5.08k
    oidc_json_decref(json); /* jansson value is refcounted, not pooled */
70
5.08k
  }
71
72
9.03k
  apr_pool_destroy(pool);
73
9.03k
  return 0;
74
9.03k
}