/src/mod_auth_openidc/test/fuzz/fuzz_json.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 oidc_json_decode_object(): decoding of |
12 | | * attacker-controlled JSON (token responses, userinfo, metadata documents all |
13 | | * pass through here). |
14 | | */ |
15 | | |
16 | | #include "fuzz.h" |
17 | | #include "util.h" /* test fixture */ |
18 | | #include "util/util.h" /* oidc_json_decode_object */ |
19 | | |
20 | | #include "json.h" |
21 | | #include <apr_pools.h> |
22 | | #include <apr_strings.h> |
23 | | |
24 | | static int g_ready = 0; |
25 | | |
26 | | /* engine-called one-time init, pre-forkserver on AFL++: see fuzz.h */ |
27 | 34 | int LLVMFuzzerInitialize(int *argc, char ***argv) { |
28 | 34 | (void)argc; |
29 | 34 | (void)argv; |
30 | 34 | if (!g_ready) { |
31 | 34 | oidc_test_setup(); |
32 | 34 | g_ready = 1; |
33 | 34 | } |
34 | 34 | return 0; |
35 | 34 | } |
36 | | |
37 | 9.03k | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
38 | 9.03k | if (!g_ready) |
39 | 0 | LLVMFuzzerInitialize(NULL, NULL); |
40 | | |
41 | 9.03k | apr_pool_t *pool = NULL; |
42 | 9.03k | apr_pool_create(&pool, oidc_test_pool_get()); |
43 | | |
44 | 9.03k | request_rec r = *oidc_test_request_get(); |
45 | 9.03k | r.pool = pool; |
46 | | |
47 | 9.03k | char *s = apr_pstrmemdup(pool, (const char *)data, size); |
48 | 9.03k | oidc_json_t *json = NULL; |
49 | 9.03k | if ((oidc_json_decode_object(&r, s, &json) == TRUE) && (json != NULL)) |
50 | 5.08k | oidc_json_decref(json); /* jansson value is refcounted, not pooled */ |
51 | | |
52 | 9.03k | apr_pool_destroy(pool); |
53 | 9.03k | return 0; |
54 | 9.03k | } |