Durgesh February 2016

Using Address Sanitizer as an alternative to Valgrind

I have read that Address Sanitizer is an available alternative to the valgrind. So to get into it, i have started with a simple example. I have written the below given code into use_after_free.c

#include<stdio.h>
#include<stdlib.h>

int gArray[100];

int main()
{
int *arr = (int*)malloc(5*sizeof(int));
arr[1]=45;
printf("Before Free : arr[1] = %d\n",arr[1]);
free(arr);
printf("After Free : arr[1] = %d\n",arr[1]);
printf("gArray[101] : %d\n",gArray[105]);
return 0;
}

I have installed the following libraries :

1) apt-get install llvm 
2) apt-get install clang

Then I have compiled the code using the following command :

clang -O1 -g -fsanitize=address -fno-omit-frame-pointer use_after_free.c

When I executed the binary which has been created using above command, I was expecting some errors from address sanitizer. But I am getting output without any errors. Is there any thing wrong with my approach?

EDIT : I am using ubuntu 12.04, llvm 3.1 and clang 3.1

Answers


rettichschnidi February 2016

Ubuntu 12.04 brings clang 3.0, 3.3 and 3.4, but not 3.1. You are either using the 3.0 release (which does not have support for the address sanitizer and silently swallows -fsanitize=address) or you are using some unmentioned 3rd-party sources. What does clang --version tell?

For a solution: apt-get install clang-3.4 will resolve your problem.

Post Status

Asked in February 2016
Viewed 3,719 times
Voted 9
Answered 1 times

Search




Leave an answer