• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * This fuzzer exercises the agentx PDU parsing code.
17  */
18 #include <net-snmp/net-snmp-config.h>
19 #include <net-snmp/net-snmp-includes.h>
20 /* We build with the agent/mibgroup/agentx dir in an -I */
21 #include <protocol.h>
22 #include <stddef.h>
23 #include <stdint.h>
24 #include <stdlib.h>
25 
LLVMFuzzerInitialize(int * argc,char *** argv)26 int LLVMFuzzerInitialize(int *argc, char ***argv) {
27     if (getenv("NETSNMP_DEBUGGING") != NULL) {
28         /*
29          * Turn on all debugging, to help understand what
30          * bits of the parser are running.
31          */
32         snmp_enable_stderrlog();
33         snmp_set_do_debugging(1);
34         debug_register_tokens("");
35     }
36     return 0;
37 }
38 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)39 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
40     netsnmp_pdu *pdu = SNMP_MALLOC_TYPEDEF(netsnmp_pdu);
41     netsnmp_session session;
42 
43     session.version = AGENTX_VERSION_1;
44     agentx_parse(&session, pdu, (unsigned char *)data, size);
45     snmp_free_pdu(pdu);
46     return 0;
47 }
48