From owner-svn-src-all@freebsd.org Fri May 20 06:24:17 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 AB818B41C5A; Fri, 20 May 2016 06:24:17 +0000 (UTC) (envelope-from truckman@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 6C7191797; Fri, 20 May 2016 06:24:17 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4K6OGAa081582; Fri, 20 May 2016 06:24:16 GMT (envelope-from truckman@FreeBSD.org) Received: (from truckman@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4K6OGQN081581; Fri, 20 May 2016 06:24:16 GMT (envelope-from truckman@FreeBSD.org) Message-Id: <201605200624.u4K6OGQN081581@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: truckman set sender to truckman@FreeBSD.org using -f From: Don Lewis Date: Fri, 20 May 2016 06:24:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r300269 - stable/10/usr.bin/catman X-SVN-Group: stable-10 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.22 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, 20 May 2016 06:24:17 -0000 Author: truckman Date: Fri May 20 06:24:16 2016 New Revision: 300269 URL: https://svnweb.freebsd.org/changeset/base/300269 Log: MFC r299577, r299578, r299589 r299577 | truckman | 2016-05-12 16:14:31 -0700 (Thu, 12 May 2016) | 15 lines Avoid Coverity NUL termination warning about strncpy() by using memcpy() instead. It's probably a bit more optimal in this case anyway. [1] The program logic leading up to the creation of the strncpy/memcpy destination buffer is a bit hairy. Add a call to assert() to make it clear what is happening here and detect any potential buffer overruns in the future. Check a couple syscall error returns. Ignore the EEXIST error from link() to preserve existing behavior. [2] [3] r299578 | truckman | 2016-05-12 16:37:58 -0700 (Thu, 12 May 2016) | 2 lines If fchdir() fails, call err() instead of warn(). r299589 | truckman | 2016-05-12 22:49:02 -0700 (Thu, 12 May 2016) | 4 lines Instead of ignoring the EEXIST from link(), unconditionally unlink the terget before calling link(). This should prevent links to an old copy of the file from being retained. Reported by: Coverity CID: 1009659 [1], 1009349 [2], 1009350 [3] Modified: stable/10/usr.bin/catman/catman.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.bin/catman/catman.c ============================================================================== --- stable/10/usr.bin/catman/catman.c Fri May 20 06:19:00 2016 (r300268) +++ stable/10/usr.bin/catman/catman.c Fri May 20 06:24:16 2016 (r300269) @@ -34,9 +34,11 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include +#include #include #include #include @@ -267,7 +269,8 @@ get_cat_section(char *section) char *cat_section; cat_section = strdup(section); - strncpy(cat_section, "cat", 3); + assert(strlen(section) > 3 && strncmp(section, "man", 3) == 0); + memcpy(cat_section, "cat", 3); return cat_section; } @@ -419,8 +422,11 @@ process_page(char *mandir, char *src, ch fprintf(stderr, "%slink %s -> %s\n", verbose ? "\t" : "", cat, link_name); } - if (!pretend) - link(link_name, cat); + if (!pretend) { + (void) unlink(cat); + if (link(link_name, cat) < 0) + warn("%s %s: link", link_name, cat); + } return; } insert_hashtable(links, src_ino, src_dev, strdup(cat)); @@ -608,7 +614,8 @@ select_sections(const struct dirent *ent static void process_mandir(char *dir_name, char *section) { - fchdir(starting_dir); + if (fchdir(starting_dir) < 0) + err(1, "fchdir"); if (already_visited(NULL, dir_name, section == NULL)) return; check_writable(dir_name);