From owner-freebsd-current Sun Feb 9 8:39: 0 2003 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1190C37B401 for ; Sun, 9 Feb 2003 08:38:59 -0800 (PST) Received: from harmony.village.org (rover.bsdimp.com [204.144.255.66]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2303843FA3 for ; Sun, 9 Feb 2003 08:38:58 -0800 (PST) (envelope-from imp@bsdimp.com) Received: from localhost (warner@rover2.village.org [10.0.0.1]) by harmony.village.org (8.12.6/8.12.3) with ESMTP id h19Gcu3Y067881; Sun, 9 Feb 2003 09:38:56 -0700 (MST) (envelope-from imp@bsdimp.com) Date: Sun, 09 Feb 2003 09:36:00 -0700 (MST) Message-Id: <20030209.093600.122405559.imp@bsdimp.com> To: bright@mu.org Cc: current@FreeBSD.ORG Subject: Re: syslog bug From: "M. Warner Losh" In-Reply-To: <20030208210824.GK88781@elvis.mu.org> References: <20030208210824.GK88781@elvis.mu.org> X-Mailer: Mew version 2.1 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In message: <20030208210824.GK88781@elvis.mu.org> Alfred Perlstein writes: : syslog(3) botches things if you pass it a string that has "%%m" in it. : this should fix it, any comments? : : Index: syslog.c : =================================================================== : RCS file: /home/ncvs/src/lib/libc/gen/syslog.c,v : retrieving revision 1.28 : diff -u -r1.28 syslog.c : --- syslog.c 14 Nov 2002 12:40:14 -0000 1.28 : +++ syslog.c 8 Feb 2003 21:08:09 -0000 : @@ -190,12 +190,18 @@ : } : : /* Substitute error message for %m. */ : - for ( ; (ch = *fmt); ++fmt) : + for ( ; (ch = *fmt); ++fmt) { : if (ch == '%' && fmt[1] == 'm') { : ++fmt; : fputs(strerror(saved_errno), fmt_fp); : - } else : + } else if (ch == '%' && fmt[1] == '%') { : + ++fmt; : + fputc(ch, fmt_fp); : + fputc(ch, fmt_fp); : + } else { : fputc(ch, fmt_fp); : + } : + } : : /* Null terminate if room */ : fputc(0, fmt_fp); : With the above fix, "fred %%m" will produce 'fred %%ERRNO-ERROR-MESSAGE' would it not? Isn't there one too many fputc(ch, fmt_fp) in the case where you detect %%? + ++fmt; + fputc(ch, fmt_fp); instead in the '%%' if statement. This would print only one '%' ala printf. Warner To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message