Source-Changes-HG archive

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

[src/netbsd-1-6]: src/lib/libc/stdio Pull up revisions 1.16-1.17 (requested b...



details:   https://anonhg.NetBSD.org/src/rev/ceb67defa155
branches:  netbsd-1-6
changeset: 529887:ceb67defa155
user:      jmc <jmc%NetBSD.org@localhost>
date:      Fri Jan 10 06:33:17 2003 +0000

description:
Pull up revisions 1.16-1.17 (requested by kristerw in ticket #1059)
 Fix two bugs:
 1. snprintf(foo, 0. XXX) is guaranteed not to write in foo by the
    standard (ISO/IEC 9899 7.19.6.5) but our implementation handles this
    as if the buffer has a size of (size_t)-1.
 2. snprintf(NULL, 0, XXX) leaks memory since cantwrite() allocates
    memory if _bf._base == NULL, and this buffer is never freed
    (PR 16483).

diffstat:

 lib/libc/stdio/snprintf.c  |  14 ++++++++++----
 lib/libc/stdio/vsnprintf.c |  14 ++++++++++----
 2 files changed, 20 insertions(+), 8 deletions(-)

diffs (84 lines):

diff -r 55b276d8ed47 -r ceb67defa155 lib/libc/stdio/snprintf.c
--- a/lib/libc/stdio/snprintf.c Fri Jan 10 06:26:13 2003 +0000
+++ b/lib/libc/stdio/snprintf.c Fri Jan 10 06:33:17 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: snprintf.c,v 1.15 2001/12/07 11:47:43 yamt Exp $       */
+/*     $NetBSD: snprintf.c,v 1.15.2.1 2003/01/10 06:33:18 jmc Exp $    */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)snprintf.c 8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: snprintf.c,v 1.15 2001/12/07 11:47:43 yamt Exp $");
+__RCSID("$NetBSD: snprintf.c,v 1.15.2.1 2003/01/10 06:33:18 jmc Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -76,6 +76,7 @@
        va_list ap;
        FILE f;
        struct __sfileext fext;
+       unsigned char dummy[1];
 
        _DIAGASSERT(n == 0 || str != NULL);
        _DIAGASSERT(fmt != NULL);
@@ -92,8 +93,13 @@
        _FILEEXT_SETUP(&f, &fext);
        f._file = -1;
        f._flags = __SWR | __SSTR;
-       f._bf._base = f._p = (unsigned char *)str;
-       f._bf._size = f._w = n - 1;
+       if (n == 0) {
+               f._bf._base = f._p = dummy;
+               f._bf._size = f._w = 0;
+       } else {
+               f._bf._base = f._p = (unsigned char *)str;
+               f._bf._size = f._w = n - 1;
+       }
        ret = vfprintf(&f, fmt, ap);
        *f._p = 0;
        va_end(ap);
diff -r 55b276d8ed47 -r ceb67defa155 lib/libc/stdio/vsnprintf.c
--- a/lib/libc/stdio/vsnprintf.c        Fri Jan 10 06:26:13 2003 +0000
+++ b/lib/libc/stdio/vsnprintf.c        Fri Jan 10 06:33:17 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vsnprintf.c,v 1.16 2001/12/07 11:47:45 yamt Exp $      */
+/*     $NetBSD: vsnprintf.c,v 1.16.2.1 2003/01/10 06:33:17 jmc Exp $   */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)vsnprintf.c        8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: vsnprintf.c,v 1.16 2001/12/07 11:47:45 yamt Exp $");
+__RCSID("$NetBSD: vsnprintf.c,v 1.16.2.1 2003/01/10 06:33:17 jmc Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -66,6 +66,7 @@
        int ret;
        FILE f;
        struct __sfileext fext;
+       unsigned char dummy[1];
 
        _DIAGASSERT(n == 0 || str != NULL);
        _DIAGASSERT(fmt != NULL);
@@ -78,8 +79,13 @@
        _FILEEXT_SETUP(&f, &fext);
        f._file = -1;
        f._flags = __SWR | __SSTR;
-       f._bf._base = f._p = (unsigned char *)str;
-       f._bf._size = f._w = n - 1;
+       if (n == 0) {
+               f._bf._base = f._p = dummy;
+               f._bf._size = f._w = 0;
+       } else {
+               f._bf._base = f._p = (unsigned char *)str;
+               f._bf._size = f._w = n - 1;
+       }
        ret = vfprintf(&f, fmt, ap);
        *f._p = 0;
        return (ret);



Home | Main Index | Thread Index | Old Index