tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] -fsanitizer=address


From: Pascal Cuoq
Subject: Re: [Tinycc-devel] -fsanitizer=address
Date: Thu, 13 Jun 2019 14:41:35 +0000

Hello,

On 12 Jun 2019, at 21:21, Mike <address@hidden> wrote:

I've run "make test" under -fsanitize=address and got the same report for several failed tests:

This appears to be caused by an offset into a dynamically allocated block being assigned to sym in build_got_entries at line 1041:

            sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];

And this dynamically allocated block being realloc'ed as a result of calling build_got(s1) at line 1102:

                build_got(s1);

Bearing in mind that we keep using sym at line 1108:

            attr = put_got_entry(s1, reloc_type, sym->st_size, sym->st_info,
                                 sym_index);

I have no idea what I am doing, but I applied the following patch and it seems to have fixed the dangling pointer, according to the tool I use (not ASan).

diff --git a/tccelf.c b/tccelf.c
index e5f6c42..6ddfb9f 100644
--- a/tccelf.c
+++ b/tccelf.c
@@ -1098,8 +1098,10 @@ ST_FUNC void build_got_entries(TCCState *s1)
             } else
                 reloc_type = R_GLOB_DAT;

 

-            if (!s1->got)
+            if (!s1->got) {
                 build_got(s1);
+                sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; //attempt
+            }

 

             if (gotplt_entry == BUILD_GOT_ONLY)
                 continue;


Would a developer confirm this is a good idea?

Pascal

Attachment: dangling.patch
Description: dangling.patch


reply via email to

[Prev in Thread] Current Thread [Next in Thread]