1 /* 2 * 3 * honggfuzz - architecture dependent code (NETBSD/UNWIND) 4 * ----------------------------------------- 5 * 6 * Author: Kamil Rytarowski <n54@gmx.com> 7 * 8 * Copyright 2010-2018 by Google Inc. All Rights Reserved. 9 * 10 * Licensed under the Apache License, Version 2.0 (the "License"); you may 11 * not use this file except in compliance with the License. You may obtain 12 * a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software 17 * distributed under the License is distributed on an "AS IS" BASIS, 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 19 * implied. See the License for the specific language governing 20 * permissions and limitations under the License. 21 * 22 */ 23 24 #include "netbsd/unwind.h" 25 26 #include <endian.h> 27 #include <stdio.h> 28 #include <stdlib.h> 29 #include <string.h> 30 31 #include "honggfuzz.h" 32 #include "libhfcommon/common.h" 33 #include "libhfcommon/log.h" 34 35 /* 36 * Nested loop not most efficient approach, although it's assumed that list is 37 * usually target specific and thus small. 38 */ 39 char* arch_btContainsSymbol( 40 size_t symbolsListSz, char** symbolsList, size_t num_frames, funcs_t* funcs) { 41 for (size_t frame = 0; frame < num_frames; frame++) { 42 size_t len = strlen(funcs[frame].func); 43 44 /* Try only for frames that have symbol name from backtrace */ 45 if (strlen(funcs[frame].func) > 0) { 46 for (size_t i = 0; i < symbolsListSz; i++) { 47 /* Wildcard symbol string special case */ 48 char* wOff = strchr(symbolsList[i], '*'); 49 if (wOff) { 50 /* Length always > 3 as checked at input file parsing step */ 51 len = wOff - symbolsList[i] - 1; 52 } 53 54 if (strncmp(funcs[frame].func, symbolsList[i], len) == 0) { 55 return funcs[frame].func; 56 } 57 } 58 } 59 } 60 return NULL; 61 } 62