<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/87031>87031</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Sanitizer __asan_locate_address returns the incorrect size for char * literals.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
briandw
</td>
</tr>
</table>
<pre>
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, ®ion_address, ®ion_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);
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VE2PozgQ_TXFpTQRFCGBA4d0sjmN9jA7e44MFMErx45s063pX7_CkAZ60hNFOHG9evXqgxLOyatmLiF7gewUid53xpaVlUI3b1Flml_lj16j7xiduN0VY8XKvG0gPkF8-Dlcy3dG044Qb6W-okPLd2M9N1j9wstFOKEvytTC80U0jWXnUDpMN_izk-GnXxD12rISnpvLq7BToB98M6-8NqHQzRfkY_iRtjbWcu1Rsb76bgiQxBPr6rmLp-_4l1Kpa9U3jJAendDSy3e2QOcQT2rPthU1bzpI_3rq4htp_mAdCvUnZyWrL83CObZ-aQ5Pqf3UgctQS6C87oRFoIMDKmD_MsIQEYNBixtD9pJDdoJ0YRycLz6YAxFCesJ4hrwa2Qyslq_S6I-iD6i___3-_RnXBH3CttBktPOBHOiAQilTX6RuTXB42meg3AEdx0Smc0r9iEC7tcD15QgrVmJli0D5HBmowFXZho9l31u9zGjmgP1pBo9dGhjjIS7QDoHoLKTiBr3BMRes-rYdBos-q5kCLUr1YJ_bfRNSA-VB6IT53OWh_aGEQNTK9_fK-Lobwq0yn0dHsQ5w561iPZa4-A0cuvHRzvXU_eYQdKze3XHdPGQlNOpB_DwTdyu1b0OGNOuD9IBAWQPZUYfCHRfiPwdfUnyofsIw2xYEc8kf6yFqyrQp0kJEXCb7JNnt99uiiLqSt9m2ooq4qHf7_W7XFpTXWbwvci6qJG8jWVJM2zilIk6yPCk26bbK2kTwbltkVRunsI35JqTaKPV62xh7jaRzPZf5Pk6TSImKlQuLmkjzGwbjID47RbYcfL5V_dXBNlbSeTezeOkVl_88dtiXO3MYt3FnSv3YmqHFrbEfs4RKerZCuQ1GvVVl5_3dQXoAOgOdr9J3fbWpzQ3oPAiYjm93a_7j2gOdg2wHdA5p_R8AAP__rF_2yA">