blob: 594140186701c6d9cc7c0d998445abf1f28aa086 [file] [log] [blame]
Craig Tiller71c610d2016-03-18 15:57:08 -07001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
Craig Tiller71c610d2016-03-18 15:57:08 -07004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
Craig Tiller8da85112016-06-10 09:13:10 -070034#include <stdbool.h>
Craig Tiller71c610d2016-03-18 15:57:08 -070035#include <stdint.h>
36#include <string.h>
37
38#include <grpc/support/alloc.h>
39
Craig Tillerfdef23f2016-03-28 14:25:43 -070040#include "src/core/lib/http/parser.h"
Craig Tiller71c610d2016-03-18 15:57:08 -070041
Craig Tiller8da85112016-06-10 09:13:10 -070042bool squelch = true;
43bool leak_check = true;
44
Craig Tiller71c610d2016-03-18 15:57:08 -070045int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
Craig Tiller21239742016-03-23 16:33:28 -070046 grpc_http_parser parser;
Craig Tillerf707d622016-05-06 14:26:12 -070047 grpc_http_request request;
48 memset(&request, 0, sizeof(request));
49 grpc_http_parser_init(&parser, GRPC_HTTP_REQUEST, &request);
Craig Tiller71c610d2016-03-18 15:57:08 -070050 gpr_slice slice = gpr_slice_from_copied_buffer((const char *)data, size);
Craig Tillerf707d622016-05-06 14:26:12 -070051 GRPC_ERROR_UNREF(grpc_http_parser_parse(&parser, slice));
52 GRPC_ERROR_UNREF(grpc_http_parser_eof(&parser));
Craig Tiller71c610d2016-03-18 15:57:08 -070053 gpr_slice_unref(slice);
Craig Tiller21239742016-03-23 16:33:28 -070054 grpc_http_parser_destroy(&parser);
Craig Tillerf707d622016-05-06 14:26:12 -070055 grpc_http_request_destroy(&request);
Craig Tiller71c610d2016-03-18 15:57:08 -070056 return 0;
57}