Re: library/6182: Bad catclose declaration cause corruption on amd64

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <bugs@...>
Date: Saturday, July 4, 2009 - 5:15 pm

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

From: Mark Kettenis <mark.kettenis@xs4all.nl>
To: henry@precheur.org
Cc: gnats@openbsd.org, bugs@cvs.openbsd.org
Subject: Re: library/6182: Bad catclose declaration cause corruption on amd64
Date: Sat, 4 Jul 2009 23:02:29 +0200 (CEST)

 > Date: Sat, 4 Jul 2009 13:17:27 -0700
 > From: Henry Precheur <henry@precheur.org>
 > In src/lib/libc/nls/_catclose.c _catclose is declared this way:
 > 
 >   extern int _catclose(nl_catd);
 > 
 > nl_catd is a type, but since the type is not declared in _catclose.c,
 > the compiler assumes that nl_catd is an integer.
 
 Eh, nl_catd is declared in <nl_types.h>, which is included right
 before that declaration.
 
 > Since pointers and integers have a different size on
 > amd64, it can cause corruptions on amd64. Here is a gdb backtrace
 > demonstrating the problem:
 > 
 > #0  _catclose (catd=0x2) at /usr/src/lib/libc/nls/catclose.c:42
 > No locals.
 > #1  0x000000020e7d95f8 in __num2string (num=2, sign=1, setid=1, 
 >     buf=0x20ec2dbe0 "No such file or directory", buflen=255, list=0x20e9f8940, max=91, 
 >     def=0x20e8f1019 "Unknown error: ") at /usr/src/lib/libc/string/strerror_r.c:106
 >         ret = 0
 >         len = 25
 >         catd = 0x202b1c020
 > 
 > catd value is not the same in strerror_r and _catclose.
 
 You're fooled by the fact that GCC generates incomplete debug
 information.  GDB managed to stop inside the function prologue and at
 that point the stack slot that is going to hold the local copy of the
 catd argument isn't filled yet.  If you step (2 times) to get out of
 the prologue and into the body of the function, you'll see that the
 catd value is the same after all.
 
 Cheers,
 
 Mark
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: library/6182: Bad catclose declaration cause corruption ..., Mark Kettenis, (Sat Jul 4, 5:15 pm)