login
Header Space

 
 

Re: vsnprintf broken

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <users@...>
Date: Wednesday, May 14, 2008 - 11:47 am

I think I found the problem. At least the following patch taken
from FreeBSD fixes the issue for me:

Index: lib/libc/stdio/vsnprintf.c
===================================================================
RCS file: /home/dcvs/src/lib/libc/stdio/vsnprintf.c,v
retrieving revision 1.8
diff -r1.8 vsnprintf.c
53c53
<       char dummy;
---
63c63,65
<                 str = &dummy;
---


The FreeBSD commit message is:

revision 1.22
date: 2003-07-02 00:08:44 -0700;  author: jkh;  state: Exp;  lines: +5 -3;
When size is 1 should just null terminate the string.  The dummy variable
is made an array of two, to explicitly avoid stack corruption due to
null-terminating (which is doesn't actually happen due to stack alignment
padding).

Submitted by: Ed Moy <emoy@apple.com>
Obtained from: Apple Computer, Inc.


Does anyone understand, why more than one byte may be written if n = 1?

Cheers,
Johannes


Simon 'corecode' Schubert <corecode@fs.ei.tum.de> wrote:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: vsnprintf broken, Johannes Hofmann, (Wed May 14, 11:47 am)
speck-geostationary