vsnprintf(3) memory leak patch, misc/26044 and bin/36175

2002-09-12 Thread Maxim Konovalov


Hello -current,

Our vsnprintf(3) has a memory leak, take a look at

http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/36175 and

http://www.freebsd.org/cgi/query-pr.cgi?pr=misc/26044

for details.

Any objections against a patch below (from OpenBSD)?

Index: libc/stdio/vsnprintf.c
===
RCS file: /home/ncvs/src/lib/libc/stdio/vsnprintf.c,v
retrieving revision 1.20
diff -u -r1.20 vsnprintf.c
--- libc/stdio/vsnprintf.c  6 Sep 2002 11:23:56 -   1.20
+++ libc/stdio/vsnprintf.c  12 Sep 2002 07:55:53 -
@@ -50,6 +50,7 @@
 {
size_t on;
int ret;
+   char dummy;
FILE f;
struct __sFILEX ext;

@@ -58,6 +59,11 @@
n--;
if (n  INT_MAX)
n = INT_MAX;
+   /* Stdio internals do not deal correctly with zero length buffer */
+   if (n == 0) {
+str = dummy;
+n = 1;
+   }
f._file = -1;
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;

%%%

-- 
Maxim Konovalov, MAcomnet, Internet Dept., system engineer
phone: +7 (095) 796-9079, mailto:[EMAIL PROTECTED]



To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: vsnprintf(3) memory leak patch, misc/26044 and bin/36175

2002-09-12 Thread Kris Kennaway

On Thu, Sep 12, 2002 at 12:02:45PM +0400, Maxim Konovalov wrote:

 + /* Stdio internals do not deal correctly with zero length buffer */

I thought ache fixed a lot of these; are you sure the situation still
applies to -current?

Kris



msg42930/pgp0.pgp
Description: PGP signature


Re: vsnprintf(3) memory leak patch, misc/26044 and bin/36175

2002-09-12 Thread Maxim Konovalov

On 18:46+0400, Sep 12, 2002, Kris Kennaway wrote:

 On Thu, Sep 12, 2002 at 12:02:45PM +0400, Maxim Konovalov wrote:

  +   /* Stdio internals do not deal correctly with zero length buffer */

 I thought ache fixed a lot of these; are you sure the situation still
 applies to -current?

Yes, it still leaks. Testcase from misc/26044:

main() {for(;;) vsnprintf(0, 0, yadda yadda!\n);};

-- 
Maxim Konovalov, MAcomnet, Internet Dept., system engineer
phone: +7 (095) 796-9079, mailto:[EMAIL PROTECTED]



To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message