From owner-svn-src-all@freebsd.org Fri Sep 9 07:10:51 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 68B2EBD21A1; Fri, 9 Sep 2016 07:10:51 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1F79F974; Fri, 9 Sep 2016 07:10:51 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u897AoCb051363; Fri, 9 Sep 2016 07:10:50 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u897AoSQ051362; Fri, 9 Sep 2016 07:10:50 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201609090710.u897AoSQ051362@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Fri, 9 Sep 2016 07:10:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r305651 - head/usr.sbin/newsyslog X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Sep 2016 07:10:51 -0000 Author: ed Date: Fri Sep 9 07:10:50 2016 New Revision: 305651 URL: https://svnweb.freebsd.org/changeset/base/305651 Log: Properly patch up dirname()/basename() calls to not clobber ent->log. It turns out that we had a couple of more calls to dirname()/basename() in newsyslog(8) that assume the input isn't clobbered. This is bad, because it apparently breaks log rotation now that the new dirname() implementation has been merged. Fix this by first copying the input and then calling dirname()/basename(). While there, improve the naming of variables in this function a bit. Reported by: Ryan Steinmetz, gjb Reviewed by: bdrewery, allanjude Differential Revision: https://reviews.freebsd.org/D7838 Modified: head/usr.sbin/newsyslog/newsyslog.c Modified: head/usr.sbin/newsyslog/newsyslog.c ============================================================================== --- head/usr.sbin/newsyslog/newsyslog.c Fri Sep 9 07:00:50 2016 (r305650) +++ head/usr.sbin/newsyslog/newsyslog.c Fri Sep 9 07:10:50 2016 (r305651) @@ -1510,11 +1510,11 @@ validate_old_timelog(int fd, const struc static void delete_oldest_timelog(const struct conf_entry *ent, const char *archive_dir) { - char *logfname, *s, *dir, errbuf[80]; + char *basebuf, *dirbuf, errbuf[80]; + const char *base, *dir; int dir_fd, i, logcnt, max_logcnt; struct oldlog_entry *oldlogs; struct dirent *dp; - const char *cdir; struct tm tm; DIR *dirp; @@ -1522,19 +1522,19 @@ delete_oldest_timelog(const struct conf_ max_logcnt = MAX_OLDLOGS; logcnt = 0; - if (archive_dir != NULL && archive_dir[0] != '\0') - cdir = archive_dir; - else - if ((cdir = dirname(ent->log)) == NULL) - err(1, "dirname()"); - if ((dir = strdup(cdir)) == NULL) - err(1, "strdup()"); + if (archive_dir != NULL && archive_dir[0] != '\0') { + dirbuf = NULL; + dir = archive_dir; + } else { + if ((dirbuf = strdup(ent->log)) == NULL) + err(1, "strdup()"); + dir = dirname(dirbuf); + } - if ((s = basename(ent->log)) == NULL) - err(1, "basename()"); - if ((logfname = strdup(s)) == NULL) + if ((basebuf = strdup(ent->log)) == NULL) err(1, "strdup()"); - if (strcmp(logfname, "/") == 0) + base = basename(basebuf); + if (strcmp(base, "/") == 0) errx(1, "Invalid log filename - became '/'"); if (verbose > 2) @@ -1545,7 +1545,7 @@ delete_oldest_timelog(const struct conf_ err(1, "Cannot open log directory '%s'", dir); dir_fd = dirfd(dirp); while ((dp = readdir(dirp)) != NULL) { - if (validate_old_timelog(dir_fd, dp, logfname, &tm) == 0) + if (validate_old_timelog(dir_fd, dp, base, &tm) == 0) continue; /* @@ -1610,8 +1610,8 @@ delete_oldest_timelog(const struct conf_ free(oldlogs[i].fname); } free(oldlogs); - free(logfname); - free(dir); + free(dirbuf); + free(basebuf); } /*