public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* sanitizer not detecting buffer overrun
@ 2023-11-12  0:01 Navin P
  2023-11-12  2:34 ` Sam James
  2023-11-12  9:37 ` Jonathan Wakely
  0 siblings, 2 replies; 5+ messages in thread
From: Navin P @ 2023-11-12  0:01 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1370 bytes --]

Hi,

Why doesn't sanitizer catch this ? The value ptr is a valid address but it
did a buffer overflow into another object a3 and then it is a valid
address. This is from production code where a ptr whose base was different
array address overflows into another array and becomes a valid address.
This is not caught by address sanitizer.

   - How do you detect this and fix this ? Are there any alternative
   datastructures in C or C++ that prevent these kind of overruns
   Please don't increase the cookie or red zone size between arrays. Again
   sizes more than the cookie or redzone between arrays or objects can be
   overrun



navin@Navin-acer-5740:~/cpp$ gcc -fsanitize=address sanitizer.c
navin@Navin-acer-5740:~/cpp$ ./a.out
a1=(0x614000000040-0x6140000001d0) a2=(0x614000000240-0x6140000003d0)
a3=(0x614000000440-0x6140000005d0)
value=0, ptr=0x614000000498
ptr lies in the array a3
navin@Navin-acer-5740:~/cpp$ cat sanitizer.c
#include<stdlib.h>
#include<stdio.h>
int main(){
int *a1=calloc(100,sizeof(int));
int *a2=calloc(100,sizeof(int));
int *a3=calloc(100,sizeof(int));

printf("a1=(%p-%p) a2=(%p-%p) a3=(%p-%p)\n",a1,a1+100,a2,a2+100,a3,a3+100);
int *ptr=a2;
ptr+=150;
printf("value=%d, ptr=%p\n",*ptr,ptr);
if(a3<=ptr && ptr<=a3+100) printf("ptr lies in the array a3\n");

free(a1);
free(a2);
free(a3);
}
navin@Navin-acer-5740:~/cpp$


Regards,
Navin

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-11-12 10:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-12  0:01 sanitizer not detecting buffer overrun Navin P
2023-11-12  2:34 ` Sam James
2023-11-12  5:14   ` Navin P
2023-11-12 10:02     ` Xi Ruoyao
2023-11-12  9:37 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).