NetBSD-Bugs archive

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

Re: toolchain/59549: gdb is not ctype(3) safe



The following reply was made to PR toolchain/59549; it has been noted by GNATS.

From: RVP <rvp%SDF.ORG@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: toolchain/59549: gdb is not ctype(3) safe
Date: Sat, 26 Jul 2025 12:06:11 +0000 (UTC)

 On Sat, 26 Jul 2025, Thomas Klausner via gnats wrote:
 
 > The backtrace of Guitar when it segfaults looks wrong though:
 >
 > Thread 12 "" received signal SIGSEGV, Segmentation fault.
 > [Switching to LWP 26550 of process 27435]
 > 0x000000000069d346 in __gmtime_r50 (t=0x7cb9f8ffe7f8, tm=0x7cba003bdf80 <tm>) at file/src/gmtime_r.c:13
 > warning: 13     file/src/gmtime_r.c: No such file or directory
 > (gdb) bt
 > #0  0x000000000069d346 in __gmtime_r50 (t=0x7cb9f8ffe7f8, tm=0x7cba003bdf80 <tm>) at file/src/gmtime_r.c:13
 > #1  0x000000000069d366 in __gmtime_r50 (t=<optimized out>, tm=0x7cba003bdf80 <tm>) at file/src/gmtime_r.c:14
 > #2  0x000000000069d366 in __gmtime_r50 (t=<optimized out>, tm=0x7cba003bdf80 <tm>) at file/src/gmtime_r.c:14
 > ... and so on for more than 15000 frames, until I stopped it...
 >
 > (gdb) p *t
 > $1 = 1753523442
 > (gdb) p *tm
 > $2 = {tm_sec = 42, tm_min = 50, tm_hour = 11, tm_mday = 26, tm_mon = 6, tm_year = 125, tm_wday = 6, tm_yday = 206, tm_isdst = 1, tm_gmtoff = 7200, tm_zone = 0x7cb9fb1d846c "CEST"}
 >
 > Probably stack corruption, because why else would the same function be there >15000 times.
 >
 
 No, that's the trouble: it _is_ being called recursively because:
 
 Guitar-1.3.0/filetype/file/src/gmtime_r.c has:
 
   11 struct tm *
   12 gmtime_r(const time_t *t, struct tm *tm)
   13 {
   14         struct tm *tmp = gmtime(t);
              [...]
   19 }
 
 and src/lib/libc/time/localtime.c has:
 
 1871 struct tm * 
 1872 gmtime(const time_t *timep) 
 1873 { 
 1874 # if !SUPPORT_C89 
 1875   static struct tm tm; 
 1876 # endif 
 1877   return gmtime_r(timep, &tm); 
 1878 }
 
 This will call gmtime_r() back in Guitar; which will call gmtime() in libc ...
 
 
 This object (gmtime_r.o) shouldn't unconditionally be added into libfiletype.a
 in Guitar-1.3.0/filetype/Makefile.
 
 Remove it, and _this_ crash should go away.
 
 -RVP
 


Home | Main Index | Thread Index | Old Index