public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "shaohua.li at inf dot ethz.ch" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug sanitizer/108023] New: Incorrect line number in ASAN's report
Date: Thu, 08 Dec 2022 15:11:28 +0000	[thread overview]
Message-ID: <bug-108023-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             reply	other threads:[~2022-12-08 15:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-08 15:11 shaohua.li at inf dot ethz.ch [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-108023-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).