source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mandoc: When checking cross references with -Tlint, ultimately fall back
@ 2017-07-01 12:54 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2017-07-01 12:54 UTC (permalink / raw)
  To: source

Log Message:
-----------
When checking cross references with -Tlint, ultimately fall back to
looking in the current working directory.  Not a security issue 
because the files are never open(2)ed, only access(2)ed.
Requested by jmc@ and inspired by mdoclint(1).

This cannot be perfect because it only works for files having the
exact filename ./pagename.sec - mandoc has no way to figure out
which files might contain a manual for multiple names, or that files 
in autohell might be called ./pagename.man.in instead, or which
subdirectories might contain additional source files.  Also, it may
hide messages if you have bogus stuff lying around in the directory
where you run mandoc -Tlint.  But jmc@ considers it important, and
good enough for everyday use.

Also avoid leaking the memory for the file name while here.

Modified Files:
--------------
    mandoc:
        main.c

Revision Data
-------------
Index: main.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/main.c,v
retrieving revision 1.295
retrieving revision 1.296
diff -Lmain.c -Lmain.c -u -p -r1.295 -r1.296
--- main.c
+++ main.c
@@ -663,14 +663,23 @@ fs_lookup(const struct manpaths *paths, 
 	if (globres == 0)
 		file = mandoc_strdup(*globinfo.gl_pathv);
 	globfree(&globinfo);
-	if (globres != 0)
+	if (globres == 0)
+		goto found;
+	if (res != NULL || ipath + 1 != paths->sz)
 		return 0;
 
+	mandoc_asprintf(&file, "%s.%s", name, sec);
+	globres = access(file, R_OK);
+	free(file);
+	return globres != -1;
+
 found:
 	warnx("outdated mandoc.db lacks %s(%s) entry, run %s %s",
 	    name, sec, BINM_MAKEWHATIS, paths->paths[ipath]);
-	if (res == NULL)
+	if (res == NULL) {
+		free(file);
 		return 1;
+	}
 	*res = mandoc_reallocarray(*res, ++*ressz, sizeof(struct manpage));
 	page = *res + (*ressz - 1);
 	page->file = file;
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-07-01 12:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-01 12:54 mandoc: When checking cross references with -Tlint, ultimately fall back schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).