Issue 87031
Summary Sanitizer __asan_locate_address returns the incorrect size for char * literals.
Labels new issue
Assignees
Reporter briandw
    Run the sample below.
The size of the string s reported by __asan_locate_address is 3. This is the size of unrelated_var.
Remove unrelated_var and __asan_locate_address reports the correct length of 10.


```
#include <sanitizer/asan_interface.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

int string_size(char *s){
    char name[8];
    size_t name_size = 0;
 void *region_address = NULL;
    size_t region_size = 0;

    const void* alloc_info = __asan_locate_address(s, name, name_size, &region_address, &region_size);
    if (alloc_info) {
        return region_size;
 }
    assert (0 && "Failed to locate buffer");
    return 0;
}

int main() 
{
    char *s = "fizzbotch";
    int string_len = strlen(s);
    int asan_size = string_size(s);
    char unrelated_var[] = "12";  

    printf("string_len: %d\n", string_len);
    printf("asan_size: %d\n", asan_size);
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to