1 /* Copyright 2021 Google LLC 2 Licensed under the Apache License, Version 2.0 (the "License"); 3 you may not use this file except in compliance with the License. 4 You may obtain a copy of the License at 5 http://www.apache.org/licenses/LICENSE-2.0 6 Unless required by applicable law or agreed to in writing, software 7 distributed under the License is distributed on an "AS IS" BASIS, 8 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 See the License for the specific language governing permissions and 10 limitations under the License. 11 */ 12 #include "../cachedb/test/test_cachedb.h" 13 #include "../lib/test/test_csv.h" 14 #include "../mem/test/test_malloc.h" 15 #include "../str.h" 16 #include "../ut.h" 17 #include "../lib/csv.h" 18 19 #include "../context.h" 20 #include "../dprint.h" 21 #include "../globals.h" 22 #include "../lib/list.h" 23 #include "../sr_module.h" 24 #include "../sr_module_deps.h" 25 LLVMFuzzerTestOneInput(const char * data,size_t size)26int LLVMFuzzerTestOneInput(const char *data, size_t size) { 27 // Ensure we have one byte for the "decider" variable 28 if (size == 0) { 29 return 0; 30 } 31 char *decider = *data; 32 data++; 33 size--; 34 35 ensure_global_context(); 36 struct sip_uri u; 37 38 char *new_str = (char *)malloc(size + 1); 39 if (new_str == NULL) { 40 return 0; 41 } 42 memcpy(new_str, data, size); 43 new_str[size] = '\0'; 44 45 csv_record *ret = NULL; 46 if (((int)decider % 2) == 0) { 47 ret = parse_csv_record(_str(new_str)); 48 } 49 else { 50 ret = _parse_csv_record(_str(new_str), CSV_RFC_4180); 51 } 52 free_csv_record(ret); 53 free(new_str); 54 } 55