How to disable clang AddressSanitizer instrumentation for a function on FreeBSD?
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 18 Jan 2022 13:03:46 UTC
Hi I'm trying to skip clang AddressSanitizer instrumentation for isMatch(void *ptr) function. How to do this on FreeBSD? My test program: #include <string.h>#include <stdio.h>#include <stdlib.h> #define PATTERN1 0x4ffcf694 static unsigned char pattern1[] = {0x4f,0xfc,0xf6,0x94}; __attribute__((no_sanitize("address"))) int isMatch(void *ptr); int main(int argc, char *argv[]){ int rv = 0; void *ptr = NULL; ptr = malloc(4); if (!ptr) { printf("No memory."); exit(1); } /* Copy PATTERN1 marker to the allocated block */ memcpy(ptr, pattern1, sizeof(pattern1)); /* TEST 1: Correct case. */ printf("TEST 1: Correct case.\n"); rv = isMatch(ptr); if (rv == 1) printf("Matched\n"); else printf("NOT Matched\n"); /* TEST 2: ptr - 1000 */ printf("TEST 2: ptr - 1000\n"); rv = isMatch(ptr - 1000); if (rv == 1) printf("Matched\n"); else printf("NOT Matched\n"); } __attribute__((no_sanitize("address"))) int isMatch(void *ptr){ if ((memcmp(ptr, (void *)pattern1, sizeof(pattern1)) == 0)) return 1; return 0;} /usr/local/bin/clang13 prog.c -O1 -g -fsanitize=address -fno-omit-frame-pointer -Wall -O -I. -I/usr/local/include -L. -L/usr/local/lib -o prog When run I get following:./progTEST 1: Correct case.MatchedTEST 2: ptr - 1000AddressSanitizer:DEADLYSIGNAL===================================================================29072==ERROR: AddressSanitizer: SEGV on unknown address 0x601ffff00010 (pc 0x0000002bb794 bp 0x7fffffffea30 sp 0x7fffffffea30 T0)==29072==The signal is caused by a READ memory access. #0 0x2bb794 in isMatch path/prog.c:67:7 #1 0x2bb73e in main path/prog.c:56:7 #2 0x236d3f in _start /usr/src/lib/csu/amd64/crt1_c.c:75:7 #3 0x8002e2007 (<unknown module>) AddressSanitizer can not provide additional info.SUMMARY: AddressSanitizer: SEGV path/prog.c:67:7 in isMatch==29072==ABORTING Appreciate any help. Best regardsSagara