Mercurial > illumos > illumos-gate
changeset 13117:f8c2d8257841
6224042 man command dumps core if there is a long filename starting with man or cat in a man directory.
author | Rich Burridge <rich.burridge@oracle.com> |
---|---|
date | Fri, 13 Aug 2010 14:49:55 -0700 |
parents | 6fa1bbe65855 |
children | 98bb3694e858 |
files | usr/src/cmd/man/src/man.c |
diffstat | 1 files changed, 18 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/usr/src/cmd/man/src/man.c Fri Aug 13 12:20:44 2010 -0700 +++ b/usr/src/cmd/man/src/man.c Fri Aug 13 14:49:55 2010 -0700 @@ -95,7 +95,6 @@ #define PLEN 3 /* prefix length {man, cat, fmt} */ #define TMPLEN 7 /* length of tmpfile prefix */ #define MAXTOKENS 64 -#define MAXSUFFIX 20 /* length of section suffix */ #define DOT_SO ".so " #define PREPROC_SPEC "'\\\" " @@ -814,8 +813,8 @@ char **dirv; char **dv; char **p; - char prev[MAXSUFFIX]; - char tmp[MAXSUFFIX]; + char *prev = NULL; + char *tmp = NULL; int plen; int maxentries = MAXTOKENS; int entries = 0; @@ -839,8 +838,6 @@ malloc_error(); } - (void) memset(tmp, 0, MAXSUFFIX); - (void) memset(prev, 0, MAXSUFFIX); for (dv = dirv, p = manp->secv; *dv; dv++) { plen = PLEN; if (match(*dv, SGMLDIR, PLEN+1)) @@ -852,14 +849,26 @@ continue; } + if (tmp != NULL) + free(tmp); + tmp = strdup(*dv + plen); + if (tmp == NULL) + malloc_error(); (void) sprintf(tmp, "%s", *dv + plen); - if (strcmp(prev, tmp) == 0) { - /* release memory allocated by sortdir */ - free(*dv); - continue; + if (prev != NULL) { + if (strcmp(prev, tmp) == 0) { + /* release memory allocated by sortdir */ + free(*dv); + continue; + } } + if (prev != NULL) + free(prev); + prev = strdup(*dv + plen); + if (prev == NULL) + malloc_error(); (void) sprintf(prev, "%s", *dv + plen); /* * copy the string in (*dv + plen) to *p