| Code Coverage: vinyl-cache/bin/vinyld/fuzzers/esi_parse_fuzzer.c |
| |
| 82217aa4fc7094b3610340078afaf78cd95a8ec9 |
| |
| 0 |
|
/*- |
| 1 |
|
* Copyright (c) 2018 Varnish Software AS |
| 2 |
|
* All rights reserved. |
| 3 |
|
* |
| 4 |
|
* Author: Federico G. Schwindt <fgsch@lodoss.net> |
| 5 |
|
* |
| 6 |
|
* SPDX-License-Identifier: BSD-2-Clause |
| 7 |
|
* |
| 8 |
|
* Redistribution and use in source and binary forms, with or without |
| 9 |
|
* modification, are permitted provided that the following conditions |
| 10 |
|
* are met: |
| 11 |
|
* 1. Redistributions of source code must retain the above copyright |
| 12 |
|
* notice, this list of conditions and the following disclaimer. |
| 13 |
|
* 2. Redistributions in binary form must reproduce the above copyright |
| 14 |
|
* notice, this list of conditions and the following disclaimer in the |
| 15 |
|
* documentation and/or other materials provided with the distribution. |
| 16 |
|
* |
| 17 |
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 18 |
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 |
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 |
|
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
| 21 |
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 |
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 23 |
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 |
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 25 |
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 26 |
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 |
|
* SUCH DAMAGE. |
| 28 |
|
* |
| 29 |
|
* ESI parser fuzzer. |
| 30 |
|
*/ |
| 31 |
|
|
| 32 |
|
#include "config.h" |
| 33 |
|
|
| 34 |
|
#include <string.h> |
| 35 |
|
#include <stdlib.h> |
| 36 |
|
#include <stdio.h> |
| 37 |
|
|
| 38 |
|
#include "cache/cache_int.h" |
| 39 |
|
#include "cache/cache_vgz.h" /* enum vgz_flag */ |
| 40 |
|
#include "cache/cache_esi.h" |
| 41 |
|
#include "cache/cache_filter.h" /* struct vfp_ctx */ |
| 42 |
|
#include "cache/cache_obj.h" /* cache_filter.h uses ObjVAI */ |
| 43 |
|
|
| 44 |
|
#include "vfil.h" |
| 45 |
|
|
| 46 |
|
int LLVMFuzzerTestOneInput(const uint8_t *, size_t); |
| 47 |
|
|
| 48 |
|
struct VSC_main *VSC_C_main; |
| 49 |
|
volatile struct params *cache_param; |
| 50 |
|
|
| 51 |
|
int |
| 52 |
|
PAN__DumpStruct(struct vsb *vsb, int block, int track, const void *ptr, |
| 53 |
|
const char *smagic, unsigned magic, const char *fmt, ...) |
| 54 |
0 |
{ |
| 55 |
0 |
(void)vsb; |
| 56 |
0 |
(void)block; |
| 57 |
0 |
(void)track; |
| 58 |
0 |
(void)ptr; |
| 59 |
0 |
(void)smagic; |
| 60 |
0 |
(void)magic; |
| 61 |
0 |
(void)fmt; |
| 62 |
0 |
return (0); |
| 63 |
0 |
} |
| 64 |
|
|
| 65 |
|
void |
| 66 |
|
VSL(enum VSL_tag_e tag, vxid_t vxid, const char *fmt, ...) |
| 67 |
108169 |
{ |
| 68 |
108169 |
(void)tag; |
| 69 |
108169 |
(void)vxid; |
| 70 |
108169 |
(void)fmt; |
| 71 |
108169 |
} |
| 72 |
|
|
| 73 |
|
void |
| 74 |
|
VSLb(struct vsl_log *vsl, enum VSL_tag_e tag, const char *fmt, ...) |
| 75 |
145450 |
{ |
| 76 |
145450 |
(void)vsl; |
| 77 |
145450 |
(void)tag; |
| 78 |
145450 |
(void)fmt; |
| 79 |
145450 |
} |
| 80 |
|
|
| 81 |
|
void |
| 82 |
|
VSLb_ts(struct vsl_log *l, const char *event, vtim_real first, vtim_real *pprev, |
| 83 |
|
vtim_real now) |
| 84 |
0 |
{ |
| 85 |
0 |
(void)l; |
| 86 |
0 |
(void)event; |
| 87 |
0 |
(void)first; |
| 88 |
0 |
(void)pprev; |
| 89 |
0 |
(void)now; |
| 90 |
0 |
} |
| 91 |
|
|
| 92 |
|
int |
| 93 |
|
ObjVAIlease(struct worker *wrk, vai_hdl vhdl, struct vscarab *scarab) |
| 94 |
|
{ |
| 95 |
|
|
| 96 |
|
(void)wrk; |
| 97 |
|
(void)vhdl; |
| 98 |
|
(void)scarab; |
| 99 |
|
return (0); |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
void |
| 103 |
|
ObjVAIreturn(struct worker *wrk, vai_hdl vhdl, struct vscaret *scaret) |
| 104 |
|
{ |
| 105 |
|
(void)wrk; |
| 106 |
|
(void)vhdl; |
| 107 |
|
(void)scaret; |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
void |
| 111 |
|
WRK_Log(enum VSL_tag_e tag, const char *fmt, ...) |
| 112 |
0 |
{ |
| 113 |
|
|
| 114 |
0 |
(void)tag; |
| 115 |
0 |
(void)fmt; |
| 116 |
0 |
} |
| 117 |
|
|
| 118 |
|
int |
| 119 |
|
LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) |
| 120 |
0 |
{ |
| 121 |
0 |
struct VSC_main __VSC_C_main; |
| 122 |
0 |
struct params __cache_param; |
| 123 |
0 |
struct http req[1]; |
| 124 |
0 |
struct http resp[1]; |
| 125 |
0 |
struct vfp_ctx vc[1]; |
| 126 |
0 |
struct worker wrk[1]; |
| 127 |
0 |
struct ws ws[1]; |
| 128 |
0 |
struct vep_state *vep; |
| 129 |
0 |
struct vsb *vsb; |
| 130 |
0 |
txt hd[HTTP_HDR_URL + 1]; |
| 131 |
0 |
struct vep_flags flags = {0}; |
| 132 |
0 |
char ws_buf[1024]; |
| 133 |
|
|
| 134 |
0 |
if (size < 1) |
| 135 |
0 |
return (0); |
| 136 |
|
|
| 137 |
0 |
AN(data); |
| 138 |
|
|
| 139 |
0 |
VSC_C_main = &__VSC_C_main; |
| 140 |
0 |
cache_param = &__cache_param; |
| 141 |
|
|
| 142 |
0 |
memset(&__cache_param, 0, sizeof(__cache_param)); |
| 143 |
0 |
if (data[0] & 0x8f) |
| 144 |
0 |
flags.esi_ignore_https = 1; |
| 145 |
0 |
if (size > 1 && data[1] & 0x8f) |
| 146 |
0 |
flags.esi_disable_xml_check = 1; |
| 147 |
0 |
if (size > 2 && data[2] & 0x8f) |
| 148 |
0 |
flags.esi_ignore_other_elements = 1; |
| 149 |
0 |
if (size > 3 && data[3] & 0x8f) |
| 150 |
0 |
flags.esi_remove_bom = 1; |
| 151 |
|
|
| 152 |
|
/* Setup ws */ |
| 153 |
0 |
WS_Init(ws, "req", ws_buf, sizeof ws_buf); |
| 154 |
|
|
| 155 |
|
/* Setup req */ |
| 156 |
0 |
INIT_OBJ(req, HTTP_MAGIC); |
| 157 |
0 |
req->hd = hd; |
| 158 |
0 |
req->hd[HTTP_HDR_URL].b = "/"; |
| 159 |
0 |
req->ws = ws; |
| 160 |
|
|
| 161 |
|
/* Setup resp */ |
| 162 |
0 |
INIT_OBJ(resp, HTTP_MAGIC); |
| 163 |
0 |
resp->ws = ws; |
| 164 |
|
|
| 165 |
|
/* Setup wrk */ |
| 166 |
0 |
INIT_OBJ(wrk, WORKER_MAGIC); |
| 167 |
|
|
| 168 |
|
/* Setup vc */ |
| 169 |
0 |
INIT_OBJ(vc, VFP_CTX_MAGIC); |
| 170 |
0 |
vc->wrk = wrk; |
| 171 |
0 |
vc->resp = resp; |
| 172 |
|
|
| 173 |
0 |
vep = VEP_Init(vc, req, NULL, NULL, flags); |
| 174 |
|
|
| 175 |
0 |
AN(vep); |
| 176 |
0 |
VEP_Parse(vep, (const char *)data, size); |
| 177 |
0 |
vsb = VEP_Finish(vep); |
| 178 |
0 |
if (vsb != NULL) |
| 179 |
0 |
VSB_destroy(&vsb); |
| 180 |
0 |
WS_Rollback(ws, 0); |
| 181 |
|
|
| 182 |
0 |
return (0); |
| 183 |
0 |
} |
| 184 |
|
|
| 185 |
|
#if defined(TEST_DRIVER) |
| 186 |
|
int |
| 187 |
|
main(int argc, char **argv) |
| 188 |
|
{ |
| 189 |
|
ssize_t len; |
| 190 |
|
char *buf; |
| 191 |
|
int i; |
| 192 |
|
|
| 193 |
|
for (i = 1; i < argc; i++) { |
| 194 |
|
len = 0; |
| 195 |
|
buf = VFIL_readfile(NULL, argv[i], &len); |
| 196 |
|
AN(buf); |
| 197 |
|
LLVMFuzzerTestOneInput((uint8_t *)buf, len); |
| 198 |
|
free(buf); |
| 199 |
|
} |
| 200 |
|
} |
| 201 |
|
#endif |