summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2021-09-04 22:37:27 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2021-09-04 22:37:27 +0000
commit3d518e494bea68beb82113f2665896a88b0b1776 (patch)
tree36f6a7ab2f00f050bc6ec92a1a496794cae59ac6
parent093195b40a5b74db25c085e14b3796a8eb82e4b2 (diff)
during prioritization for man(1), correctly extract the section name
from the file name extension of gzipped manual page files; bug found on Alpine Linux by Soeren Tempel <soeren at soeren hyphen tempel dot net>, who also tested this patch
-rw-r--r--usr.bin/mandoc/main.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c
index 643228037f2..a6c7341b6d3 100644
--- a/usr.bin/mandoc/main.c
+++ b/usr.bin/mandoc/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.259 2021/09/04 12:47:04 schwarze Exp $ */
+/* $OpenBSD: main.c,v 1.260 2021/09/04 22:37:26 schwarze Exp $ */
/*
* Copyright (c) 2010-2012, 2014-2021 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -131,7 +131,7 @@ main(int argc, char *argv[])
struct mparse *mp; /* Opaque parser object. */
const char *conf_file; /* -C: alternate config file. */
const char *os_s; /* -I: Operating system for display. */
- const char *progname, *sec;
+ const char *progname, *sec, *ep;
char *defpaths; /* -M: override manpaths. */
char *auxpaths; /* -m: additional manpaths. */
char *oarg; /* -O: output option string. */
@@ -514,11 +514,16 @@ main(int argc, char *argv[])
sec++; /* Prefer without suffix. */
if (*sec != '/')
prio += 10; /* Wrong dir name. */
- if (search.sec != NULL &&
- (strlen(sec) <= ssz + 3 ||
- strcmp(sec + strlen(sec) - ssz,
- search.sec) != 0))
- prio += 20; /* Wrong file ext. */
+ if (search.sec != NULL) {
+ ep = strchr(sec, '\0');
+ if (ep - sec > 3 &&
+ strncmp(ep - 3, ".gz", 3) == 0)
+ ep -= 3;
+ if ((size_t)(ep - sec) < ssz + 3 ||
+ strncmp(ep - ssz, search.sec,
+ ssz) != 0) /* Wrong file */
+ prio += 20; /* extension. */
+ }
if (prio >= best_prio)
continue;
best_prio = prio;