bin/51519: newsyslog handles bzip2-compressed files incorrectly
Lukas Ertl
l.ertl at univie.ac.at
Fri May 2 03:15:30 PDT 2003
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 Mon Apr 28 00:37:31 2003
+++ usr.sbin/newsyslog/newsyslog.c Thu 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 @@
printf("%s <%d>: ", ent->log, ent->numlogs);
}
size = sizefile(ent->log);
- modtime = age_old_log(ent->log);
+ modtime = age_old_log(ent->log, ent->flags);
ent->rotate = 0;
ent->firstcreate = 0;
if (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)
{
struct stat sb;
- char tmp[MAXPATHLEN + sizeof(".0") + sizeof(COMPRESS_POSTFIX) + 1];
+ char tmp[MAXPATHLEN + 1];
+ char *suffix;
+
+ if (flags & CE_COMPACT)
+ suffix = COMPRESS_POSTFIX;
+ else if (flags & CE_BZCOMPACT)
+ suffix = BZCOMPRESS_POSTFIX;
+ else
+ suffix = "";
if (archtodir) {
char *p;
@@ -1493,9 +1501,12 @@
(void) strlcpy(tmp, file, sizeof(tmp));
}
- if (stat(strcat(tmp, ".0"), &sb) < 0)
- if (stat(strcat(tmp, COMPRESS_POSTFIX), &sb) < 0)
+ strlcat(tmp, ".0", sizeof(tmp));
+ if (stat(tmp, &sb) < 0) {
+ strlcat(tmp, suffix, sizeof(tmp));
+ if (stat(tmp, &sb) < 0)
return (-1);
+ }
return ((int)(timenow - sb.st_mtime + 1800) / 3600);
}
--- newsyslog.c.diff ends here ---
regards,
le
--
Lukas Ertl eMail: l.ertl at univie.ac.at
UNIX-Systemadministrator Tel.: (+43 1) 4277-14073
Zentraler Informatikdienst (ZID) Fax.: (+43 1) 4277-9140
der Universität Wien http://mailbox.univie.ac.at/~le/
More information about the freebsd-bugs
mailing list