summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2020-01-26 11:16:47 +0000
committerIngo Schwarze <schwarze@openbsd.org>2020-01-26 11:16:47 +0000
commitff5d1b6807b6b1831313e20d894e7761bf88f864 (patch)
tree7e5e0c03e47ded01f9f2f9c35dbcfbb5038cadb5
parent9a0648ee1954e83311194a35ce390db361aeac67 (diff)
downloadmandoc-ff5d1b6807b6b1831313e20d894e7761bf88f864.tar.gz
Fix incorrect file type tests.
This bug caused sockets and character special devices to be accepted as manual pages if they appeared inside manpaths, and it caused incorrect file names to be entered into the database when the manpath or one of its parent directories was a symbolic link. This fixes the issues reported by <Andreas dot Kahari at abc dot se> on ports@, but additional issues remain when symbolic links are contained in a manpath that involves another symbolic link.
-rw-r--r--mandocdb.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/mandocdb.c b/mandocdb.c
index 378f3008..b4bf19e3 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -801,7 +801,7 @@ filescan(const char *file)
exitcode = (int)MANDOCLEVEL_BADARG;
say(file, "&lstat");
return;
- } else if ((st.st_mode & (S_IFREG | S_IFLNK)) == 0) {
+ } else if (S_ISREG(st.st_mode) == 0 && S_ISLNK(st.st_mode) == 0) {
exitcode = (int)MANDOCLEVEL_BADARG;
say(file, "Not a regular file");
return;
@@ -840,7 +840,7 @@ filescan(const char *file)
* Note the stat(2) can still fail if the link target
* doesn't exist.
*/
- if (st.st_mode & S_IFLNK) {
+ if (S_ISLNK(st.st_mode)) {
if (stat(buf, &st) == -1) {
exitcode = (int)MANDOCLEVEL_BADARG;
say(file, "&stat");