<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54733>54733</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
ASAN trace files reporting Wrong line number when call_back function is used
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
shailendrakharwar13
</td>
</tr>
</table>
<pre>
Problem -
Asan does not clean existing error for same process and keep appending on top of it .
so if many errors happened in same process asan call back will always report same error stack .
callback is getting appended for errors in the program while on stderr it reports correct error.
Easily Reproducible example -(asan_demo.c)
// code placeholder
#include<stdio.h>
#include<stdlib.h>
#include "asan_interface.h"
void asan_error(const char *s);
void asan_error(const char *s)
{ printf("Start printing \n");
printf("%s\n", s);
printf("End dump \n");
s=NULL;
}
int main(int argc, char **argv)
{
__asan_set_error_report_callback(asan_error);
int *array = (int *) malloc(10*sizeof(int));
free(array);
// some code
printf("some random message \n");
int *a = (int*)malloc(4*sizeof(int));
array[1] =10;
a[0] =1;
int *b = (int*)malloc(4*sizeof(int));
int *c = (int*)malloc(4*sizeof(int));
array[1]=1; free(a);
free(b);
//a[10]=1;
}
In another file "asan_interface.h" for registering the call back function(which will be called when error happens) , the code is -
void __asan_set_error_report_callback(void (*callback)(const char *));
Command used to run the file -
gcc -fsanitize=address -fsanitize-recover=address -g1 asan_demo.c > & l
Output -
Error reported in callback:
1st Error
==3003403==ERROR: AddressSanitizer: heap-use-after-free on address 0x604000000014 at pc 0x0000004008db bp 0x7ffd576b0240 sp 0x7ffd576b0230
WRITE of size 4 at 0x604000000014 thread T0
{{ #0 0x4008da in main /scratch/asan_example.c:23}}
{{ #1 0x7f314cb08554 in __libc_start_main (/lib64/libc.so.6+0x22554)}}
{{ #2 0x400778 (/scratch/a.out+0x400778)}}
2nd Error:
==3003403==ERROR: AddressSanitizer: heap-use-after-free on address 0x604000000014 at pc 0x0000004008db bp 0x7ffd576b0240 sp 0x7ffd576b0230
WRITE of size 4 at 0x604000000014 thread T0
#0 0x4008da in main /scratch/asan_example.c:23
#1 0x7f314cb08554 in __libc_start_main (/lib64/libc.so.6+0x22554)
#2 0x400778 (/scratch/a.out+0x400778)
and so on :
Though multiple error(at line no 23 and 27 are occuring ) . In the call back we get the first line indicating the error at line 23 for first error and for second error we get an appended trace of (error at line 23 followed by error at line 27)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzdVsmO2zgQ_Rr7QtiQJcuWDz64ux0gQJAMOhnkaFAUZXEiiQZJtdPz9fOKlLy1Z8lMTtOLF7L46tWiV8x18br-xei8lg2bjKKnUbTZWN6yQkvLWu2YqCW-yu_KOtXumTRGG1bi3_JGsoPRQlrLeFuwb1IeGD8cZFuQpW6Z0wemS6YcmwZoq5kqWcPb1wBkWeUPyIKp9gaRWAhe1yzn4hs7Knzi9ZG_WmbkQRsXzAMf68imd0KH_BllGdtL53kHXvBD1HvfcOkq73FveMPYsVK1ZETcugI2RDz4skxoY6Rw4WjvKLxuuVX1K3uWwCk6oZBKpIs3B7xPRnFGgewK2eipGMWr_mT8Dn8ALeC-5kJWuobHYTNRrai7Qo6SRzBRelqNku39zVrld3fZKI69Z9U6aUq4gFkcB7MXrQqf4J0PBySFbi1qXXGDgxtLRJOHyyh_4GCwXz4wZBbeS1jB82fHUTO_QvUYpY8t8blwxK4PjOLUnqwemf0L0y26r-iaw5-g2lHy9PHXDx_OIS2fLqMCEHpS4WRGH7nZC_I4BIU_LL0AlJ1j68F3O58NK13IyC70y27owaH-fbouaZErD234KwND1rv3HlcgVNcaPLJZRIlVv0tdBguCuUIqjZTkiJCud_o-sxpPSui2YecyfX7b4BHWDWvw7PG9vJ_JgfIF3cD2RHb-d1wDyfRhNkqfCAbRXWxiIxo23vrN_4PfHkL8JOo9wXPu71Ykv1cNCnIWnTGunrKhMd-3kFQNdYLWkijdf5q9mBm5hzZLQ08VydlZM8uuFU5p6mtIm6iCiObBBF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