Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Nov 1998 23:12:24 -0800 (PST)
From:      Archie Cobbs <archie@whistle.com>
To:        freebsd-current@FreeBSD.ORG
Subject:   snprintf() in the kernel
Message-ID:  <199811190712.XAA23068@bubba.whistle.com>

next in thread | raw e-mail | index | archive | help
I would like to do the following:

 1. Add snprintf() to kern/subr_prf.c

 2. Change all appropriate uses of sprintf() and/or strcat()
    to use snprintf() instead.

The main reason for doing this is not to add kernel bloat :-) but
rather to improve the reliability and maintainability of the kernel.

In fact, the total byte count may even go down due to the several
instances in the code that are forced to do their own bounds checking
(the changes to subr_prf.c are minimal).

Cases where it's "obvious" that the buffer can't overflow will
be left alone, for some conservative definition of "obvious".

A typical example:

  RCS file: /home/ncvs/src/sys/alpha/tc/espvar.h,v
  retrieving revision 1.1
  diff -u -r1.1 espvar.h
  --- espvar.h    1998/08/20 08:27:10     1.1
  +++ espvar.h    1998/11/19 07:03:55
  @@ -74,8 +74,7 @@
   #define ECB_TRACE(ecb, msg, a, b) do { \
	  const char *f = "[" msg "]"; \
	  int n = strlen((ecb)->trace); \
  -       if (n < (sizeof((ecb)->trace)-100)) \
  -               sprintf((ecb)->trace + n, f,  a, b); \
  +       snprintf((ecb)->trace + n, sizeof((ecb)->trace) - n, f, a, b); \
   } while(0)
   #else
   #define ECB_TRACE(ecb, msg, a, b)

I count 131 files that use sprintf() and 28 that use strcat(), so
this will touch a lot of files (but hopefully for the better).

So.. does anyone have a huge problem with doing this before I jump in?
[ Anyone willing to review for me? ]

Thanks,
-Archie

___________________________________________________________________________
Archie Cobbs   *   Whistle Communications, Inc.  *   http://www.whistle.com

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199811190712.XAA23068>