Source-Changes-HG archive

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

[src/trunk]: src va_{start,end} audit:



details:   https://anonhg.NetBSD.org/src/rev/07fc617ed900
branches:  trunk
changeset: 515423:07fc617ed900
user:      wiz <wiz%NetBSD.org@localhost>
date:      Mon Sep 24 13:22:25 2001 +0000

description:
va_{start,end} audit:
Make sure that each va_start has one and only one matching va_end,
especially in error cases.
If the va_list is used multiple times, do multiple va_starts/va_ends.
If a function gets va_list as argument, don't let it use va_end (since
it's the callers responsibility).

Improved by comments from enami and christos -- thanks!

Heimdal/krb4/KAME changes already fed back, rest to follow.

Inspired by, but not not based on, OpenBSD.

diffstat:

 bin/pax/tty_subs.c                       |   8 ++--
 bin/rcp/rcp.c                            |  24 +++++++++----
 bin/sh/output.c                          |   5 +-
 crypto/dist/heimdal/appl/ftp/ftp/ftp.c   |  10 +++--
 crypto/dist/heimdal/appl/rcp/rcp.c       |  10 +++--
 crypto/dist/heimdal/lib/roken/snprintf.c |   6 ++-
 crypto/dist/kame/racoon/plog.c           |  11 ++++--
 crypto/dist/krb4/lib/roken/snprintf.c    |  14 +++++--
 crypto/dist/openssl/crypto/err/err.c     |   1 +
 dist/bind/bin/irpd/irpd.c                |   3 +-
 dist/bind/bin/ndc/ndc.c                  |   3 +-
 dist/bind/lib/irs/irp.c                  |   4 +-
 dist/dhcp/omapip/alloc.c                 |   2 +
 dist/dhcp/server/failover.c              |   9 ++++-
 dist/ntp/ntpd/refclock_true.c            |   5 +-
 games/larn/io.c                          |   5 +-
 games/sail/pl_7.c                        |   8 ++--
 gnu/dist/gettext/lib/vasprintf.c         |   1 +
 gnu/dist/libiberty/vasprintf.c           |   1 +
 gnu/dist/toolchain/opcodes/arc-dis.c     |   1 +
 lib/libc/stdio/asprintf.c                |  16 ++++----
 lib/libcurses/ctrace.c                   |  15 ++++----
 lib/libcurses/printw.c                   |  14 ++++----
 lib/libedit/el.c                         |   7 ++-
 libexec/ftpd/ftpd.c                      |   8 +++-
 libexec/rexecd/rexecd.c                  |   5 +-
 libexec/rshd/rshd.c                      |   5 +-
 sbin/fsck_msdos/main.c                   |   5 +-
 sbin/restore/utilities.c                 |   5 +-
 sbin/routed/main.c                       |  19 +++++++---
 sbin/routed/trace.c                      |   9 ++++-
 sys/arch/arm32/ofw/openfirm.c            |  10 ++++-
 sys/arch/dnard/ofw/openfirm.c            |  10 ++++-
 sys/arch/macppc/stand/ofwboot/Locore.c   |  10 ++++-
 sys/arch/mipsco/stand/common/saio.c      |   4 +-
 sys/arch/pc532/pc532/umprintf.c          |   9 +++-
 sys/arch/pmax/stand/common/rz.c          |   3 +-
 sys/arch/powerpc/powerpc/openfirm.c      |  10 ++++-
 sys/arch/sparc/sparc/openfirm.c          |  10 ++++-
 sys/arch/sparc64/sparc64/openfirm.c      |  10 ++++-
 sys/lib/libsa/subr_prf.c                 |   3 +-
 sys/netiso/tp_cons.c                     |   4 +-
 sys/netkey/key.c                         |   3 +-
 usr.bin/error/touch.c                    |  16 ++++----
 usr.bin/make/parse.c                     |   7 +--
 usr.bin/rdist/server.c                   |  56 ++++++++++++++++++++++---------
 usr.bin/telnet/telnet.c                  |   5 +-
 usr.sbin/lpr/lpd/printjob.c              |  14 ++++----
 usr.sbin/map-mbone/mapper.c              |  21 +++++------
 usr.sbin/mrinfo/mrinfo.c                 |  18 +++++-----
 usr.sbin/mtrace/mtrace.c                 |  23 ++++++------
 usr.sbin/pkg_install/lib/exec.c          |   5 +-
 usr.sbin/pppd/chat/chat.c                |   6 ++-
 usr.sbin/rarpd/rarpd.c                   |  16 ++++++++-
 usr.sbin/route6d/route6d.c               |   6 +-
 usr.sbin/sup/source/run.c                |   6 ++-
 usr.sbin/sup/source/supcmeat.c           |   3 +-
 usr.sbin/sup/source/supcmisc.c           |   3 +-
 usr.sbin/sup/source/supmsg.c             |  11 +++++-
 usr.sbin/user/user.c                     |   8 ++--
 60 files changed, 342 insertions(+), 207 deletions(-)

diffs (truncated from 2049 to 300 lines):

diff -r 93c3be23faa1 -r 07fc617ed900 bin/pax/tty_subs.c
--- a/bin/pax/tty_subs.c        Mon Sep 24 13:19:54 2001 +0000
+++ b/bin/pax/tty_subs.c        Mon Sep 24 13:22:25 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tty_subs.c,v 1.8 2000/02/17 03:12:27 itohy Exp $       */
+/*     $NetBSD: tty_subs.c,v 1.9 2001/09/24 13:22:25 wiz Exp $ */
 
 /*-
  * Copyright (c) 1992 Keith Muller.
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)tty_subs.c 8.2 (Berkeley) 4/18/94";
 #else
-__RCSID("$NetBSD: tty_subs.c,v 1.8 2000/02/17 03:12:27 itohy Exp $");
+__RCSID("$NetBSD: tty_subs.c,v 1.9 2001/09/24 13:22:25 wiz Exp $");
 #endif
 #endif /* not lint */
 
@@ -122,13 +122,13 @@
 #endif
 {
        va_list ap;
+       if (ttyoutf == NULL)
+               return;
 #      if __STDC__
        va_start(ap, fmt);
 #      else
        va_start(ap);
 #      endif
-       if (ttyoutf == NULL)
-               return;
        (void)vfprintf(ttyoutf, fmt, ap);
        va_end(ap);
        (void)fflush(ttyoutf);
diff -r 93c3be23faa1 -r 07fc617ed900 bin/rcp/rcp.c
--- a/bin/rcp/rcp.c     Mon Sep 24 13:19:54 2001 +0000
+++ b/bin/rcp/rcp.c     Mon Sep 24 13:22:25 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rcp.c,v 1.27 2001/01/04 15:39:51 lukem Exp $   */
+/*     $NetBSD: rcp.c,v 1.28 2001/09/24 13:22:25 wiz Exp $     */
 
 /*
  * Copyright (c) 1983, 1990, 1992, 1993
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)rcp.c      8.2 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: rcp.c,v 1.27 2001/01/04 15:39:51 lukem Exp $");
+__RCSID("$NetBSD: rcp.c,v 1.28 2001/09/24 13:22:25 wiz Exp $");
 #endif
 #endif /* not lint */
 
@@ -932,23 +932,31 @@
 {
        static FILE *fp;
        va_list ap;
+
+       ++errs;
+       if (fp == NULL && !(fp = fdopen(rem, "w")))
+               return;
+
 #if __STDC__
        va_start(ap, fmt);
 #else
        va_start(ap);
 #endif
 
-       ++errs;
-       if (fp == NULL && !(fp = fdopen(rem, "w")))
-               return;
        (void)fprintf(fp, "%c", 0x01);
        (void)fprintf(fp, "rcp: ");
        (void)vfprintf(fp, fmt, ap);
        (void)fprintf(fp, "\n");
        (void)fflush(fp);
+       va_end(ap);
 
-       if (!iamremote)
+       if (!iamremote) {
+#if __STDC__
+               va_start(ap, fmt);
+#else
+               va_start(ap);
+#endif
                vwarnx(fmt, ap);
-
-       va_end(ap);
+               va_end(ap);
+       }
 }
diff -r 93c3be23faa1 -r 07fc617ed900 bin/sh/output.c
--- a/bin/sh/output.c   Mon Sep 24 13:19:54 2001 +0000
+++ b/bin/sh/output.c   Mon Sep 24 13:22:25 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: output.c,v 1.23 2001/01/07 23:39:07 lukem Exp $        */
+/*     $NetBSD: output.c,v 1.24 2001/09/24 13:22:26 wiz Exp $  */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)output.c   8.2 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: output.c,v 1.23 2001/01/07 23:39:07 lukem Exp $");
+__RCSID("$NetBSD: output.c,v 1.24 2001/09/24 13:22:26 wiz Exp $");
 #endif
 #endif /* not lint */
 
@@ -316,6 +316,7 @@
        outc('\0', &strout);
        if (strout.flags & OUTPUT_ERR)
                outbuf[length - 1] = '\0';
+       va_end(ap);
 }
 
 /*
diff -r 93c3be23faa1 -r 07fc617ed900 crypto/dist/heimdal/appl/ftp/ftp/ftp.c
--- a/crypto/dist/heimdal/appl/ftp/ftp/ftp.c    Mon Sep 24 13:19:54 2001 +0000
+++ b/crypto/dist/heimdal/appl/ftp/ftp/ftp.c    Mon Sep 24 13:22:25 2001 +0000
@@ -32,7 +32,7 @@
  */
 
 #include "ftp_locl.h"
-RCSID ("$Id: ftp.c,v 1.1.1.3 2001/02/11 13:51:18 assar Exp $");
+RCSID ("$Id: ftp.c,v 1.2 2001/09/24 13:22:26 wiz Exp $");
 
 struct sockaddr_storage hisctladdr_ss;
 struct sockaddr *hisctladdr = (struct sockaddr *)&hisctladdr_ss;
@@ -277,15 +277,17 @@
        return (0);
     }
     oldintr = signal(SIGINT, cmdabort);
-    va_start(ap, fmt);
     if(debug){
        printf("---> ");
        if (strncmp("PASS ", fmt, 5) == 0)
            printf("PASS XXXX");
-       else 
+       else {
+           va_start(ap, fmt);
            vfprintf(stdout, fmt, ap);
-       va_start(ap, fmt);
+           va_end(ap);
+       }
     }
+    va_start(ap, fmt);
     sec_vfprintf(cout, fmt, ap);
     va_end(ap);
     if(debug){
diff -r 93c3be23faa1 -r 07fc617ed900 crypto/dist/heimdal/appl/rcp/rcp.c
--- a/crypto/dist/heimdal/appl/rcp/rcp.c        Mon Sep 24 13:19:54 2001 +0000
+++ b/crypto/dist/heimdal/appl/rcp/rcp.c        Mon Sep 24 13:22:25 2001 +0000
@@ -684,21 +684,23 @@
 {
        static FILE *fp;
        va_list ap;
-       va_start(ap, fmt);
 
        ++errs;
        if (fp == NULL && !(fp = fdopen(remout, "w")))
                return;
+       va_start(ap, fmt);
        fprintf(fp, "%c", 0x01);
        fprintf(fp, "rcp: ");
        vfprintf(fp, fmt, ap);
        fprintf(fp, "\n");
        fflush(fp);
+       va_end(ap);
 
-       if (!iamremote)
+       if (!iamremote) {
+               va_start(ap, fmt);
                vwarnx(fmt, ap);
-
-       va_end(ap);
+               va_end(ap);
+       }
 }
 
 /*
diff -r 93c3be23faa1 -r 07fc617ed900 crypto/dist/heimdal/lib/roken/snprintf.c
--- a/crypto/dist/heimdal/lib/roken/snprintf.c  Mon Sep 24 13:19:54 2001 +0000
+++ b/crypto/dist/heimdal/lib/roken/snprintf.c  Mon Sep 24 13:22:25 2001 +0000
@@ -33,7 +33,7 @@
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
-RCSID("$Id: snprintf.c,v 1.1.1.4 2001/09/17 12:25:07 assar Exp $");
+RCSID("$Id: snprintf.c,v 1.2 2001/09/24 13:22:26 wiz Exp $");
 #endif
 #include <stdio.h>
 #include <stdarg.h>
@@ -496,6 +496,7 @@
 
   va_start(args, format);
   ret = vsnprintf (str, sz, format, args);
+  va_end(args);
 
 #ifdef PARANOIA
   {
@@ -506,14 +507,15 @@
     if (tmp == NULL)
       abort ();
 
+    va_start(args, format);
     ret2 = vsprintf (tmp, format, args);
+    va_end(args);
     if (ret != ret2 || strcmp(str, tmp))
       abort ();
     free (tmp);
   }
 #endif
 
-  va_end(args);
   return ret;
 }
 #endif
diff -r 93c3be23faa1 -r 07fc617ed900 crypto/dist/kame/racoon/plog.c
--- a/crypto/dist/kame/racoon/plog.c    Mon Sep 24 13:19:54 2001 +0000
+++ b/crypto/dist/kame/racoon/plog.c    Mon Sep 24 13:22:25 2001 +0000
@@ -130,13 +130,16 @@
 
        newfmt = plog_common(pri, fmt, func);
 
-       va_start(ap, fmt);
-       if (f_foreground)
+       if (f_foreground) {
+               va_start(ap, fmt);
                vprintf(newfmt, ap);
+               va_end(ap);
+       }
 
-       if (logfile)
+       va_start(ap, fmt);
+       if (logfile) {
                log_vaprint(logp, newfmt, ap);
-       else {
+       } else {
                if (pri < ARRAYLEN(ptab))
                        vsyslog(ptab[pri].priority, newfmt, ap);
                else
diff -r 93c3be23faa1 -r 07fc617ed900 crypto/dist/krb4/lib/roken/snprintf.c
--- a/crypto/dist/krb4/lib/roken/snprintf.c     Mon Sep 24 13:19:54 2001 +0000
+++ b/crypto/dist/krb4/lib/roken/snprintf.c     Mon Sep 24 13:22:25 2001 +0000
@@ -33,7 +33,7 @@
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
-RCSID("$Id: snprintf.c,v 1.1.1.3 2001/09/17 12:09:57 assar Exp $");
+RCSID("$Id: snprintf.c,v 1.2 2001/09/24 13:22:27 wiz Exp $");
 #endif
 #include <stdio.h>
 #include <stdarg.h>
@@ -496,6 +496,7 @@
 
   va_start(args, format);
   ret = vsnprintf (str, sz, format, args);
+  va_end(args);
 
 #ifdef PARANOIA
   {
@@ -506,14 +507,15 @@
     if (tmp == NULL)
       abort ();
 
+    va_start(args, format);
     ret2 = vsprintf (tmp, format, args);
+    va_end(args);
     if (ret != ret2 || strcmp(str, tmp))
       abort ();
     free (tmp);
   }
 #endif
 
-  va_end(args);
   return ret;
 }
 #endif
@@ -527,6 +529,7 @@
 
   va_start(args, format);
   val = vasprintf (ret, format, args);
+  va_end(args);
 
 #ifdef PARANOIA
   {
@@ -536,14 +539,15 @@
     if (tmp == NULL)
       abort ();
 
+    va_start(args, format);
     ret2 = vsprintf (tmp, format, args);
+    va_end(args);
     if (val != ret2 || strcmp(*ret, tmp))
       abort ();
     free (tmp);
   }
 #endif
 
-  va_end(args);



Home | Main Index | Thread Index | Old Index