Source-Changes-HG archive

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

[src/trunk]: src/dist/am-utils Make it compile with WAUDIT=2 and FORMAT_AUDIT...



details:   https://anonhg.NetBSD.org/src/rev/50cf056bda27
branches:  trunk
changeset: 499486:50cf056bda27
user:      wiz <wiz%NetBSD.org@localhost>
date:      Tue Nov 21 01:35:36 2000 +0000

description:
Make it compile with WAUDIT=2 and FORMAT_AUDIT set. Based on tips
by Bill Sommerfeld.
Also, don't change code that's not in our path (replacing vnprintf
with vsnprintf in !HAVE_VSNPRINTF case).

diffstat:

 dist/am-utils/fsinfo/fsi_lex.l  |   4 ++--
 dist/am-utils/fsinfo/fsi_util.c |  12 ++++++------
 dist/am-utils/fsinfo/fsinfo.h   |  20 +++++++++++++-------
 dist/am-utils/libamu/xutil.c    |  27 +++++++++++++++++++--------
 4 files changed, 40 insertions(+), 23 deletions(-)

diffs (194 lines):

diff -r 33bca35d905c -r 50cf056bda27 dist/am-utils/fsinfo/fsi_lex.l
--- a/dist/am-utils/fsinfo/fsi_lex.l    Tue Nov 21 00:37:49 2000 +0000
+++ b/dist/am-utils/fsinfo/fsi_lex.l    Tue Nov 21 01:35:36 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fsi_lex.l,v 1.1.1.2 2000/11/19 23:44:32 wiz Exp $      */
+/*     $NetBSD: fsi_lex.l,v 1.2 2000/11/21 01:35:36 wiz Exp $  */
 
 %{
 /*
@@ -238,7 +238,7 @@
   va_start(ap, fmt);
   col_cleanup(0);
   fprintf(stderr, "%s:%d: ", fsi_filename ? fsi_filename : "/dev/stdin", yylineno);
-  fprintf(stderr, fmt, ap);
+  vfprintf(stderr, fmt, ap);
   fputc('\n', stderr);
   parse_errors++;
   va_end(ap);
diff -r 33bca35d905c -r 50cf056bda27 dist/am-utils/fsinfo/fsi_util.c
--- a/dist/am-utils/fsinfo/fsi_util.c   Tue Nov 21 00:37:49 2000 +0000
+++ b/dist/am-utils/fsinfo/fsi_util.c   Tue Nov 21 01:35:36 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fsi_util.c,v 1.1.1.2 2000/11/19 23:44:30 wiz Exp $     */
+/*     $NetBSD: fsi_util.c,v 1.2 2000/11/21 01:35:36 wiz Exp $ */
 
 /*
  * Copyright (c) 1997-2000 Erez Zadok
@@ -117,7 +117,7 @@
   va_start(ap, fmt);
   col_cleanup(0);
   fprintf(stderr, "%s: Error, ", progname);
-  fprintf(stderr, fmt, ap);
+  vfprintf(stderr, fmt, ap);
   fputc('\n', stderr);
   errors++;
   va_end(ap);
@@ -132,7 +132,7 @@
   va_start(ap, fmt);
   col_cleanup(0);
   fprintf(stderr, "%s:%d: ", l->i_file, l->i_line);
-  fprintf(stderr, fmt, ap);
+  vfprintf(stderr, fmt, ap);
   fputc('\n', stderr);
   errors++;
   va_end(ap);
@@ -147,7 +147,7 @@
   va_start(ap, fmt);
   col_cleanup(0);
   fprintf(stderr, "%s:%d: ", l->i_file, l->i_line);
-  fprintf(stderr, fmt, ap);
+  vfprintf(stderr, fmt, ap);
   fputc('\n', stderr);
   va_end(ap);
 }
@@ -161,7 +161,7 @@
   va_start(ap, fmt);
   col_cleanup(1);
   fprintf(stderr, "%s: Fatal, ", progname);
-  fprintf(stderr, fmt, ap);
+  vfprintf(stderr, fmt, ap);
   fputc('\n', stderr);
   va_end(ap);
   exit(1);
@@ -180,7 +180,7 @@
     va_start(ap, fmt);
     fputc('#', stdout);
     fprintf(stdout, "%s: ", progname);
-    fprintf(stdout, fmt, ap);
+    vfprintf(stdout, fmt, ap);
     putc('\n', stdout);
     va_end(ap);
   }
diff -r 33bca35d905c -r 50cf056bda27 dist/am-utils/fsinfo/fsinfo.h
--- a/dist/am-utils/fsinfo/fsinfo.h     Tue Nov 21 00:37:49 2000 +0000
+++ b/dist/am-utils/fsinfo/fsinfo.h     Tue Nov 21 01:35:36 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fsinfo.h,v 1.1.1.2 2000/11/19 23:44:31 wiz Exp $       */
+/*     $NetBSD: fsinfo.h,v 1.2 2000/11/21 01:35:36 wiz Exp $   */
 
 /*
  * Copyright (c) 1997-2000 Erez Zadok
@@ -85,15 +85,20 @@
 extern void analyze_hosts(qelem *);
 extern void compute_automount_point(char *, host *, char *);
 extern void dict_add(dict *, char *, char *);
-extern void error(char *fmt, ...);
-extern void fatal(char *fmt, ...);
+extern void error(char *fmt, ...)
+       __attribute__((__format__(__printf__, 1, 2)));
+extern void fatal(char *fmt, ...)
+       __attribute__((__format__(__printf__, 1, 2)));
 extern void gen_hdr(FILE *ef, char *hn);
 extern void info_hdr(FILE *ef, char *info);
 extern void init_que(qelem *);
 extern void ins_que(qelem *, qelem *);
-extern void lerror(ioloc *l, char *fmt, ...);
-extern void log(char *fmt, ...);
-extern void lwarning(ioloc *l, char *fmt, ...);
+extern void lerror(ioloc *l, char *fmt, ...)
+       __attribute__((__format__(__printf__, 2, 3)));
+extern void log(char *fmt, ...)
+       __attribute__((__format__(__printf__, 1, 2)));
+extern void lwarning(ioloc *l, char *fmt, ...)
+       __attribute__((__format__(__printf__, 2, 3)));
 extern void rem_que(qelem *);
 extern void set_disk_fs(disk_fs *, int, char *);
 extern void set_fsmount(fsmount *, int, char *);
@@ -102,7 +107,8 @@
 extern void show_new(char *msg);
 extern void warning(void);
 
-extern int yyerror(char *fmt, ...);
+extern int yyerror(char *fmt, ...)
+       __attribute__((__format__(__printf__, 1, 2)));
 extern void domain_strip(char *otherdom, char *localdom);
 /*
  * some systems such as DU-4.x have a different GNU flex in /usr/bin
diff -r 33bca35d905c -r 50cf056bda27 dist/am-utils/libamu/xutil.c
--- a/dist/am-utils/libamu/xutil.c      Tue Nov 21 00:37:49 2000 +0000
+++ b/dist/am-utils/libamu/xutil.c      Tue Nov 21 01:35:36 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xutil.c,v 1.2 2000/11/20 03:19:36 wiz Exp $    */
+/*     $NetBSD: xutil.c,v 1.3 2000/11/21 01:35:37 wiz Exp $    */
 
 /*
  * Copyright (c) 1997-2000 Erez Zadok
@@ -84,6 +84,9 @@
 /* forward definitions */
 static void real_plog(int lvl, const char *fmt, va_list vargs)
      __attribute__((__format__(__printf__, 2, 0)));
+/* for GCC format string auditing */
+static const char *expand_error(const char *f, char *e, int maxlen)
+     __attribute__((__format_arg__(1)));
 
 #ifdef DEBUG
 /*
@@ -288,7 +291,7 @@
  * with the current error code taken from errno.  Make sure
  * 'e' never gets longer than maxlen characters.
  */
-static void
+static const char *
 expand_error(const char *f, char *e, int maxlen)
 {
 #ifndef HAVE_STRERROR
@@ -302,7 +305,11 @@
   for (p = f, q = e; (*q = *p) && len < maxlen; len++, q++, p++) {
     if (p[0] == '%' && p[1] == 'm') {
       const char *errstr;
+#ifdef HAVE_STRERROR
+      if (error < 0)
+#else
       if (error < 0 || error >= sys_nerr)
+#endif
        errstr = NULL;
       else
 #ifdef HAVE_STRERROR
@@ -320,6 +327,7 @@
     }
   }
   e[maxlen-1] = '\0';          /* null terminate, to be sure */
+  return e;
 }
 
 
@@ -452,19 +460,22 @@
   checkup_mem();
 #endif /* DEBUG_MEM */
 
-  expand_error(fmt, efmt, 1024);
-
 #ifdef HAVE_VSNPRINTF
-  vsnprintf(ptr, 1024, efmt, vargs);
-#else /* not HAVE_VSNPRINTF */
   /*
    * XXX: ptr is 1024 bytes long, but we may write to ptr[strlen(ptr) + 2]
    * (to add an '\n', see code below) so we have to limit the string copy
    * to 1023 (including the '\0').
    */
-  fmt = efmt;
-  vsnprintf(ptr, 1023, fmt, vargs);
+  vsnprintf(ptr, 1023, expand_error(fmt, efmt, 1024), vargs);
   msg[1022] = '\0';            /* null terminate, to be sure */
+#else /* not HAVE_VSNPRINTF */
+  /*
+   * XXX: ptr is 1024 bytes long.  It is possible to write into it
+   * more than 1024 bytes, if efmt is already large, and vargs expand
+   * as well.  This is not as safe as using vsnprintf().
+   */
+  vsprintf(ptr, expand_error(fmt, efmt, 1024), vargs);
+  msg[1023] = '\0';            /* null terminate, to be sure */
 #endif /* not HAVE_VSNPRINTF */
 
   ptr += strlen(ptr);



Home | Main Index | Thread Index | Old Index