summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authortruckman <truckman@FreeBSD.org>2016-05-20 06:24:16 +0000
committertruckman <truckman@FreeBSD.org>2016-05-20 06:24:16 +0000
commiteb1ff2addcd8450cc91c4d23c26ae43f7f66bb92 (patch)
tree4d82feb77ac13526f64f0d8944abd19796e986a5 /usr.bin
parenta1ce47bacdcd56b5924833af1e14152a43b049d8 (diff)
downloadFreeBSD-src-eb1ff2addcd8450cc91c4d23c26ae43f7f66bb92.zip
FreeBSD-src-eb1ff2addcd8450cc91c4d23c26ae43f7f66bb92.tar.gz
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]
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/catman/catman.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/usr.bin/catman/catman.c b/usr.bin/catman/catman.c
index b221111..47906f5 100644
--- a/usr.bin/catman/catman.c
+++ b/usr.bin/catman/catman.c
@@ -34,9 +34,11 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/utsname.h>
+#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <err.h>
+#include <errno.h>
#include <fcntl.h>
#include <locale.h>
#include <langinfo.h>
@@ -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, char *cat, enum Ziptype zipped)
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 *entry)
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);
OpenPOWER on IntegriCloud