From owner-cvs-all Thu Jan 4 18: 8: 0 2001 From owner-cvs-all@FreeBSD.ORG Thu Jan 4 18:07:55 2001 Return-Path: Delivered-To: cvs-all@freebsd.org Received: from Awfulhak.org (awfulhak.demon.co.uk [194.222.196.252]) by hub.freebsd.org (Postfix) with ESMTP id C84D337B400; Thu, 4 Jan 2001 18:07:53 -0800 (PST) Received: from hak.lan.Awfulhak.org (root@hak.lan.Awfulhak.org [172.16.0.12]) by Awfulhak.org (8.11.1/8.11.1) with ESMTP id f0520i609972; Fri, 5 Jan 2001 02:00:44 GMT (envelope-from brian@lan.Awfulhak.org) Received: from hak.lan.Awfulhak.org (brian@localhost [127.0.0.1]) by hak.lan.Awfulhak.org (8.11.1/8.11.1) with ESMTP id f0526rB87964; Fri, 5 Jan 2001 02:06:53 GMT (envelope-from brian@hak.lan.Awfulhak.org) Message-Id: <200101050206.f0526rB87964@hak.lan.Awfulhak.org> X-Mailer: exmh version 2.2 06/23/2000 with nmh-1.0.4 To: Chris Faulhaber Cc: Will Andrews , cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org, brian@Awfulhak.org Subject: Re: cvs commit: src/usr.bin/apply apply.c In-Reply-To: Message from Chris Faulhaber of "Thu, 04 Jan 2001 14:23:31 EST." <20010104142331.D47414@peitho.fxp.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 05 Jan 2001 02:06:53 +0000 From: Brian Somers Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > On Thu, Jan 04, 2001 at 11:05:49AM -0800, Will Andrews wrote: > > will 2001/01/04 11:05:49 PST > > > > Modified files: > > usr.bin/apply apply.c > > Log: > > BDECFLAGS; de-__P()-ify, ANSIfy, use snprintf() instead of sprintf(), > > especially on strings passed from argv; rename system() to exec_shell(), > > and make it static; use strlcpy() and make sure it works; use proper > > type (size_t) to be passed to malloc()/realloc(). > > > > All the snprintf/strlcpy 'fixes' you made are quite broken since the > variables you apply sizeof() to are pointers: > > char *c, *cmd, *p, *q; > > ... > > - p += sprintf(cmd, "exec %s", argv[0]); > + p += snprintf(cmd, sizeof(cmd), "exec %s", argv[0]); > for (i = 1; i <= nargs; i++) > - p += sprintf(p, " %c%d", magic, i); > + p += snprintf(p, sizeof(p), " %c%d", magic, i); Also (and this bug was already there), s[n]printf() returns the length of what it would have liked to have put in the target, not what it actually wrote. If the first s[n]printf() above ends up truncating, the second one will happily overflow. s[n]printf() is poorly documented in this area. > -- > Chris D. Faulhaber - jedgar@fxp.org - jedgar@FreeBSD.org > -------------------------------------------------------- > FreeBSD: The Power To Serve - http://www.FreeBSD.org -- Brian Don't _EVER_ lose your sense of humour ! To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message