From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 10386 invoked from network); 4 Sep 2021 22:39:19 -0000 Received: from bsd.lv (HELO mandoc.bsd.lv) (66.111.2.12) by inbox.vuxu.org with ESMTPUTF8; 4 Sep 2021 22:39:19 -0000 Received: from fantadrom.bsd.lv (localhost [127.0.0.1]) by mandoc.bsd.lv (OpenSMTPD) with ESMTP id 19238511 for ; Sat, 4 Sep 2021 17:39:16 -0500 (EST) Received: from localhost (mandoc.bsd.lv [local]) by mandoc.bsd.lv (OpenSMTPD) with ESMTPA id 7767cebe for ; Sat, 4 Sep 2021 17:39:16 -0500 (EST) Date: Sat, 4 Sep 2021 17:39:16 -0500 (EST) X-Mailinglist: mandoc-source Reply-To: source@mandoc.bsd.lv MIME-Version: 1.0 From: schwarze@mandoc.bsd.lv To: source@mandoc.bsd.lv Subject: mandoc: during prioritization for man(1), correctly extract the section X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Message-ID: Log Message: ----------- 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 , who also tested this patch Modified Files: -------------- mandoc: main.c Revision Data ------------- Index: main.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/main.c,v retrieving revision 1.357 retrieving revision 1.358 diff -Lmain.c -Lmain.c -u -p -r1.357 -r1.358 --- main.c +++ main.c @@ -132,7 +132,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. */ @@ -536,11 +536,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; -- To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv