Module Name: src Committed By: skrll Date: Mon Jun 6 07:41:23 UTC 2022
Modified Files: src/usr.sbin/makemandb: makemandb.c Log Message: Don't index outside the mdocs array of function pointers. Analysis and suggested fixes from Tom Lane. I played it safe and went with (my variation of) the minimal fix. port-hppa/56118: sporadic app crashes in HPPA -current To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 src/usr.sbin/makemandb/makemandb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/makemandb/makemandb.c diff -u src/usr.sbin/makemandb/makemandb.c:1.62 src/usr.sbin/makemandb/makemandb.c:1.63 --- src/usr.sbin/makemandb/makemandb.c:1.62 Wed Apr 6 03:23:38 2022 +++ src/usr.sbin/makemandb/makemandb.c Mon Jun 6 07:41:23 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: makemandb.c,v 1.62 2022/04/06 03:23:38 gutteridge Exp $ */ +/* $NetBSD: makemandb.c,v 1.63 2022/06/06 07:41:23 skrll Exp $ */ /* * Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadh...@gmail.com> * Copyright (c) 2011 Kristaps Dzonsons <krist...@bsd.lv> @@ -17,7 +17,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: makemandb.c,v 1.62 2022/04/06 03:23:38 gutteridge Exp $"); +__RCSID("$NetBSD: makemandb.c,v 1.63 2022/06/06 07:41:23 skrll Exp $"); #include <sys/stat.h> #include <sys/types.h> @@ -1078,15 +1078,18 @@ mdoc_parse_Sh(const struct roff_node *n, if (n->type == ROFFT_TEXT) { mdoc_parse_section(n->sec, n->string, rec); - } else if (mdocs[n->tok] == pmdoc_Xr) { - /* - * When encountering other inline macros, - * call pmdoc_macro_handler. - */ - pmdoc_macro_handler(n, rec, MDOC_Xr); - xr_found = 1; - } else if (mdocs[n->tok] == pmdoc_Pp) { - pmdoc_macro_handler(n, rec, MDOC_Pp); + } else if (n->tok >= MDOC_Dd && n->tok < MDOC_MAX) { + const int tok_idx = n->tok - MDOC_Dd; + if (mdocs[tok_idx] == pmdoc_Xr) { + /* + * When encountering other inline macros, + * call pmdoc_macro_handler. + */ + pmdoc_macro_handler(n, rec, MDOC_Xr); + xr_found = 1; + } else if (mdocs[tok_idx] == pmdoc_Pp) { + pmdoc_macro_handler(n, rec, MDOC_Pp); + } } /*