Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Use va_copy to avoid undefined behaviour in handlin...



details:   https://anonhg.NetBSD.org/src/rev/ad028ff1b796
branches:  trunk
changeset: 771439:ad028ff1b796
user:      apb <apb%NetBSD.org@localhost>
date:      Sun Nov 20 21:27:26 2011 +0000

description:
Use va_copy to avoid undefined behaviour in handling the
va_list arg.

diffstat:

 sys/kern/subr_kmem.c |  10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diffs (43 lines):

diff -r d3e91cd0b600 -r ad028ff1b796 sys/kern/subr_kmem.c
--- a/sys/kern/subr_kmem.c      Sun Nov 20 21:02:23 2011 +0000
+++ b/sys/kern/subr_kmem.c      Sun Nov 20 21:27:26 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_kmem.c,v 1.36 2011/09/02 22:25:08 dyoung Exp $    */
+/*     $NetBSD: subr_kmem.c,v 1.37 2011/11/20 21:27:26 apb Exp $       */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_kmem.c,v 1.36 2011/09/02 22:25:08 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_kmem.c,v 1.37 2011/11/20 21:27:26 apb Exp $");
 
 #include <sys/param.h>
 #include <sys/callback.h>
@@ -473,20 +473,22 @@
 kmem_asprintf(const char *fmt, ...)
 {
        int size, str_len;
-       va_list va;
+       va_list va, va2;
        char *str;
        char buf[1];
        
        va_start(va, fmt);
+       va_copy(va2, va);
        str_len = vsnprintf(buf, sizeof(buf), fmt, va) + 1;
        va_end(va);
 
        str = kmem_alloc(str_len, KM_SLEEP);
 
-       if ((size = vsnprintf(str, str_len, fmt, va)) == -1) {
+       if ((size = vsnprintf(str, str_len, fmt, va2)) == -1) {
                kmem_free(str, str_len);
                return NULL;
        }
+       va_end(va2);
 
        return str;
 }



Home | Main Index | Thread Index | Old Index