Date: Fri, 2 May 2003 12:14:35 +0200 (=?ISO-8859-1?Q?Westeurop=E4ische_Sommerzeit?=) From: Lukas Ertl <l.ertl@univie.ac.at> To: Gregory Bond <gnb@itga.com.au> Cc: freebsd-bugs@freebsd.org Subject: Re: bin/51519: newsyslog handles bzip2-compressed files incorrectly Message-ID: <Pine.WNT.4.55.0305021208170.168@korben> In-Reply-To: <200305020148.LAA00536@lightning.itga.com.au> References: <200305020148.LAA00536@lightning.itga.com.au>
next in thread | previous in thread | raw e-mail | index | archive | help
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/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.WNT.4.55.0305021208170.168>