diff options
| author | skrll <skrll@NetBSD.org> | 2022-06-06 07:41:23 +0000 |
|---|---|---|
| committer | skrll <skrll@NetBSD.org> | 2022-06-06 07:41:23 +0000 |
| commit | 2f7c27a0f305198a7d2efa3e502d1ebcdd2f9e32 (patch) | |
| tree | 1d5ab1ae243f32c050ac8502855a459ff1ed9a57 /usr.sbin/makemandb | |
| parent | 31e093afb940462c1d6bbb54e28055b95ec1c57e (diff) | |
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
Diffstat (limited to 'usr.sbin/makemandb')
| -rw-r--r-- | usr.sbin/makemandb/makemandb.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/usr.sbin/makemandb/makemandb.c b/usr.sbin/makemandb/makemandb.c index c7065ad3a7e..78c85fdc0d8 100644 --- a/usr.sbin/makemandb/makemandb.c +++ b/usr.sbin/makemandb/makemandb.c @@ -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.upadhyay@gmail.com> * Copyright (c) 2011 Kristaps Dzonsons <kristaps@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, mandb_rec *rec) 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); + } } /* |
