From owner-freebsd-current Wed Nov 18 23:13:20 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id XAA21212 for freebsd-current-outgoing; Wed, 18 Nov 1998 23:13:20 -0800 (PST) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from whistle.com (s205m131.whistle.com [207.76.205.131]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id XAA21206 for ; Wed, 18 Nov 1998 23:13:17 -0800 (PST) (envelope-from archie@whistle.com) Received: (from smap@localhost) by whistle.com (8.7.5/8.6.12) id XAA11758 for ; Wed, 18 Nov 1998 23:12:49 -0800 (PST) Received: from bubba.whistle.com( 207.76.205.7) by whistle.com via smap (V2.0) id xma011756; Wed, 18 Nov 98 23:12:26 -0800 Received: (from archie@localhost) by bubba.whistle.com (8.8.7/8.6.12) id XAA23068 for freebsd-current@freebsd.org; Wed, 18 Nov 1998 23:12:25 -0800 (PST) From: Archie Cobbs Message-Id: <199811190712.XAA23068@bubba.whistle.com> Subject: snprintf() in the kernel To: freebsd-current@FreeBSD.ORG Date: Wed, 18 Nov 1998 23:12:24 -0800 (PST) X-Mailer: ELM [version 2.4ME+ PL38 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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