public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/108023] New: Incorrect line number in ASAN's report
@ 2022-12-08 15:11 shaohua.li at inf dot ethz.ch
  2022-12-08 21:00 ` [Bug tree-optimization/108023] " pinskia at gcc dot gnu.org
  2022-12-11 12:12 ` rguenth at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2022-12-08 15:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108023

            Bug ID: 108023
           Summary: Incorrect line number in ASAN's report
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shaohua.li at inf dot ethz.ch
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org
  Target Milestone: ---

For the following code, GCC's ASAN at -O1 and above produce incorrect line
numbers in the final reports (Line 15 v.s. Line 8).

Compiler explorer: https://godbolt.org/z/4953EPr78

% cat a.c
int a, b, c, g, f;

static long d(int);

long d(int h) {
  int **j = (int**)malloc(sizeof(int *) * sizeof(int));
  for (int i = 0; i < sizeof(int); i++)
    j[i] = malloc(sizeof(f));

  int *k = malloc(sizeof(int) * sizeof(g));

  for (h=0; h <= 2; h++) {
    free(k);
    for (b=0; b <= 2; b++)
      k[3] = j[0][h];
  }
  return k[a];
}

void e() { 
    c = d(0); 
}

int main() { 
    e();  
    return c;
}
%
% gcc-tk -O0 -fsanitize=address -w -g a.c && ./a.out
=================================================================
==3175968==ERROR: AddressSanitizer: heap-use-after-free on address
0x60200000009c at pc 0x00000040130f bp 0x7ffd47fc9fd0 sp 0x7ffd47fc9fc8
WRITE of size 4 at 0x60200000009c thread T0
    #0 0x40130e in d /a.c:15
    #1 0x4013a3 in e /a.c:21
    #2 0x4013ba in main /a.c:25
...
%
%  gcc-tk -O2 -fsanitize=address -w -g a.c && ./a.out
================================================================
==3254785==ERROR: AddressSanitizer: heap-use-after-free on address
0x60200000009c at pc 0x000000401354 bp 0x7ffce8fa2e80 sp 0x7ffce8fa2e78
WRITE of size 4 at 0x60200000009c thread T0
    #0 0x401353 in d /a.c:8
    #1 0x4010e8 in e /a.c:21
    #2 0x4010e8 in main /a.c:25
...
%

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

end of thread, other threads:[~2022-12-11 12:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-08 15:11 [Bug sanitizer/108023] New: Incorrect line number in ASAN's report shaohua.li at inf dot ethz.ch
2022-12-08 21:00 ` [Bug tree-optimization/108023] " pinskia at gcc dot gnu.org
2022-12-11 12:12 ` rguenth at gcc dot gnu.org

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).