From owner-freebsd-bugs@FreeBSD.ORG Fri May 2 03:15:30 2003 Return-Path: Delivered-To: freebsd-bugs@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0A82D37B401 for ; Fri, 2 May 2003 03:15:30 -0700 (PDT) Received: from mailbox.univie.ac.at (mailbox.univie.ac.at [131.130.1.27]) by mx1.FreeBSD.org (Postfix) with ESMTP id CC24A43F3F for ; Fri, 2 May 2003 03:15:28 -0700 (PDT) (envelope-from l.ertl@univie.ac.at) Received: from localhost (dialin202.cc.univie.ac.at [131.130.202.202]) by mailbox.univie.ac.at (8.12.2/8.12.2) with ESMTP id h42AEe2B189468; Fri, 2 May 2003 12:15:12 +0200 Date: Fri, 2 May 2003 12:14:35 +0200 (=?ISO-8859-1?Q?Westeurop=E4ische_Sommerzeit?=) From: Lukas Ertl To: Gregory Bond In-Reply-To: <200305020148.LAA00536@lightning.itga.com.au> Message-ID: References: <200305020148.LAA00536@lightning.itga.com.au> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE X-DCC-ZID-Univie-Metrics: mailbox 4251; Body=4 Fuz1=4 Fuz2=4 cc: freebsd-bugs@freebsd.org Subject: Re: bin/51519: newsyslog handles bzip2-compressed files incorrectly X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 May 2003 10:15:30 -0000 On Fri, 2 May 2003, Gregory Bond wrote: > This patch seems to leak the malloc'd "tmp" buffer. This may not be a > problem In Real Life for a 1-shot program like newsyslog. That's unfortunately correct :-). Peter has already sent me a correction about this. I didn't realize that we don't even need to malloc a tmp buffer, we could just declare a char tmp[MAXPATHLEN] and that's enough, but it was a copy'n'paste'n'no brain of the code that was already there :-) Here's the better patch from Peter: --- newsyslog.c.diff begins here --- --- usr.sbin/newsyslog/newsyslog.c.orig=09Mon Apr 28 00:37:31 2003 +++ usr.sbin/newsyslog/newsyslog.c=09Thu May 1 20:39:45 2003 @@ -143,7 +143,7 @@ static void compress_log(char *log, int dowait); static void bzcompress_log(char *log, int dowait); static int sizefile(char *file); -static int age_old_log(char *file); +static int age_old_log(char *file, int flags); static int send_signal(const struct conf_entry *ent); static time_t parse8601(char *s, char *errline); static void movefile(char *from, char *to, int perm, uid_t owner_uid, @@ -301,7 +301,7 @@ =09=09=09printf("%s <%d>: ", ent->log, ent->numlogs); =09} =09size =3D sizefile(ent->log); -=09modtime =3D age_old_log(ent->log); +=09modtime =3D age_old_log(ent->log, ent->flags); =09ent->rotate =3D 0; =09ent->firstcreate =3D 0; =09if (size < 0) { @@ -1461,10 +1461,18 @@ /* Return the age of old log file (file.0) */ static int -age_old_log(char *file) +age_old_log(char *file, int flags) { =09struct stat sb; -=09char tmp[MAXPATHLEN + sizeof(".0") + sizeof(COMPRESS_POSTFIX) + 1]; +=09char tmp[MAXPATHLEN + 1]; +=09char *suffix; + +=09if (flags & CE_COMPACT) +=09=09suffix =3D COMPRESS_POSTFIX; +=09else if (flags & CE_BZCOMPACT) +=09=09suffix =3D BZCOMPRESS_POSTFIX; +=09else +=09=09suffix =3D ""; =09if (archtodir) { =09=09char *p; @@ -1493,9 +1501,12 @@ =09=09(void) strlcpy(tmp, file, sizeof(tmp)); =09} -=09if (stat(strcat(tmp, ".0"), &sb) < 0) -=09=09if (stat(strcat(tmp, COMPRESS_POSTFIX), &sb) < 0) +=09strlcat(tmp, ".0", sizeof(tmp)); +=09if (stat(tmp, &sb) < 0) { +=09=09strlcat(tmp, suffix, sizeof(tmp)); +=09=09if (stat(tmp, &sb) < 0) =09=09=09return (-1); +=09} =09return ((int)(timenow - sb.st_mtime + 1800) / 3600); } --- newsyslog.c.diff ends here --- regards, le --=20 Lukas Ertl eMail: l.ertl@univie.ac.at UNIX-Systemadministrator Tel.: (+43 1) 4277-14073 Zentraler Informatikdienst (ZID) Fax.: (+43 1) 4277-9140 der Universit=E4t Wien http://mailbox.univie.ac.at/~le/