summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2019-05-03 17:31:15 +0000
committerIngo Schwarze <schwarze@openbsd.org>2019-05-03 17:31:15 +0000
commit07b561eee223a9b63ef21d291c1f7b04abe99fbd (patch)
tree6b0601b412c5546be35a605ea0951bc2a2233ffd
parent32580ccde20ccd7ea13428587611bd670feabbf0 (diff)
downloadmandoc-07b561eee223a9b63ef21d291c1f7b04abe99fbd.tar.gz
In fs_lookup(), use stat(2) rather than access(2) to check file existence.
Some mildly broken real-world packages on some operating systems contain dangling symlinks in manual page directories: pestering the user to run makewhatis(8) makes no sense because that won't help. On the other hand, missing read permissions deserve ugly error messages and are unlikely to occur in practice anyway. Fixing an issue reported by Lorenzo Beretta <loreb at github> as part of https://github.com/void-linux/void-packages/issues/9868 .
-rw-r--r--TODO6
-rw-r--r--main.c17
2 files changed, 11 insertions, 12 deletions
diff --git a/TODO b/TODO
index cdf256e1..55c6047a 100644
--- a/TODO
+++ b/TODO
@@ -217,12 +217,6 @@ are mere guesses, and some may be wrong.
--- missing misc features ----------------------------------------------
-- dead .so links should be entered into the database to avoid:
- man -M. lvm-config
- man: outdated mandoc.db lacks lvm-config(8) entry, run makewhatis /co/void-man
- https://github.com/void-linux/void-packages/issues/9868
- loc * exist ** algo * size * imp **
-
- man -ks 1,8 route; kn@ Jul 13, 2018 orally
- italic correction (\/) in PostScript mode
diff --git a/main.c b/main.c
index c2057e60..860fc608 100644
--- a/main.c
+++ b/main.c
@@ -21,6 +21,7 @@
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/param.h> /* MACHINE */
+#include <sys/stat.h>
#include <sys/wait.h>
#include <assert.h>
@@ -713,6 +714,7 @@ fs_lookup(const struct manpaths *paths, size_t ipath,
const char *sec, const char *arch, const char *name,
struct manpage **res, size_t *ressz)
{
+ struct stat sb;
glob_t globinfo;
struct manpage *page;
char *file;
@@ -722,13 +724,13 @@ fs_lookup(const struct manpaths *paths, size_t ipath,
form = FORM_SRC;
mandoc_asprintf(&file, "%s/man%s/%s.%s",
paths->paths[ipath], sec, name, sec);
- if (access(file, R_OK) != -1)
+ if (stat(file, &sb) != -1)
goto found;
free(file);
mandoc_asprintf(&file, "%s/cat%s/%s.0",
paths->paths[ipath], sec, name);
- if (access(file, R_OK) != -1) {
+ if (stat(file, &sb) != -1) {
form = FORM_CAT;
goto found;
}
@@ -737,7 +739,7 @@ fs_lookup(const struct manpaths *paths, size_t ipath,
if (arch != NULL) {
mandoc_asprintf(&file, "%s/man%s/%s/%s.%s",
paths->paths[ipath], sec, arch, name, sec);
- if (access(file, R_OK) != -1)
+ if (stat(file, &sb) != -1)
goto found;
free(file);
}
@@ -751,13 +753,16 @@ fs_lookup(const struct manpaths *paths, size_t ipath,
if (globres == 0)
file = mandoc_strdup(*globinfo.gl_pathv);
globfree(&globinfo);
- if (globres == 0)
- goto found;
+ if (globres == 0) {
+ if (stat(file, &sb) != -1)
+ goto found;
+ free(file);
+ }
if (res != NULL || ipath + 1 != paths->sz)
return 0;
mandoc_asprintf(&file, "%s.%s", name, sec);
- globres = access(file, R_OK);
+ globres = stat(file, &sb);
free(file);
return globres != -1;