Sat Oct 12 17:26:26 2019 UTC ()
enlarge buffer sizes


(christos)
diff -r1.37 -r1.38 src/usr.sbin/catman/catman.c

cvs diff -r1.37 -r1.38 src/usr.sbin/catman/catman.c (expand / switch to unified diff)

--- src/usr.sbin/catman/catman.c 2016/05/29 22:33:39 1.37
+++ src/usr.sbin/catman/catman.c 2019/10/12 17:26:26 1.38
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: catman.c,v 1.37 2016/05/29 22:33:39 dholland Exp $ */ 1/* $NetBSD: catman.c,v 1.38 2019/10/12 17:26:26 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Author: Baldassare Dante Profeta <dante@mclink.it> 7 * Author: Baldassare Dante Profeta <dante@mclink.it>
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE. 28 * POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32#ifndef lint 32#ifndef lint
33__RCSID("$NetBSD: catman.c,v 1.37 2016/05/29 22:33:39 dholland Exp $"); 33__RCSID("$NetBSD: catman.c,v 1.38 2019/10/12 17:26:26 christos Exp $");
34#endif /* not lint */ 34#endif /* not lint */
35 35
36#include <sys/types.h> 36#include <sys/types.h>
37#include <sys/queue.h> 37#include <sys/queue.h>
38#include <sys/param.h> 38#include <sys/param.h>
39#include <sys/stat.h> 39#include <sys/stat.h>
40#include <sys/wait.h> 40#include <sys/wait.h>
41#include <sys/utsname.h> 41#include <sys/utsname.h>
42#include <ctype.h> 42#include <ctype.h>
43#include <dirent.h> 43#include <dirent.h>
44#include <err.h> 44#include <err.h>
45#include <errno.h> 45#include <errno.h>
46#include <fnmatch.h> 46#include <fnmatch.h>
@@ -330,34 +330,34 @@ catman(void) @@ -330,34 +330,34 @@ catman(void)
330 strlcpy(catdir, mandir, sizeof(catdir)); 330 strlcpy(catdir, mandir, sizeof(catdir));
331 if (!(cp = strstr(catdir, "man/man"))) 331 if (!(cp = strstr(catdir, "man/man")))
332 continue; 332 continue;
333 cp += 4; *cp++ = 'c'; *cp++ = 'a'; *cp = 't'; 333 cp += 4; *cp++ = 'c'; *cp++ = 'a'; *cp = 't';
334 scanmandir(catdir, mandir); 334 scanmandir(catdir, mandir);
335 } 335 }
336} 336}
337 337
338static void 338static void
339scanmandir(const char *catdir, const char *mandir) 339scanmandir(const char *catdir, const char *mandir)
340{ 340{
341 TAG *buildp, *crunchp; 341 TAG *buildp, *crunchp;
342 ENTRY *e_build, *e_crunch; 342 ENTRY *e_build, *e_crunch;
343 char manpage[PATH_MAX]; 343 char manpage[2 * PATH_MAX];
344 char catpage[PATH_MAX]; 344 char catpage[2 * PATH_MAX];
345 char linkname[PATH_MAX]; 345 char linkname[PATH_MAX];
346 char buffer[PATH_MAX], *bp; 346 char buffer[PATH_MAX], *bp;
347 char tmp[PATH_MAX]; 347 char tmp[2 * PATH_MAX];
348 char buildsuff[256], buildcmd[256]; 348 char buildsuff[256], buildcmd[256];
349 char crunchsuff[256], crunchcmd[256]; 349 char crunchsuff[256], crunchcmd[256];
350 char match[256]; 350 char match[2 * 256];
351 struct stat manstat; 351 struct stat manstat;
352 struct stat catstat; 352 struct stat catstat;
353 struct stat lnkstat; 353 struct stat lnkstat;
354 struct dirent *dp; 354 struct dirent *dp;
355 DIR *dirp; 355 DIR *dirp;
356 int len, error; 356 int len, error;
357 357
358 if ((dirp = opendir(mandir)) == 0) { 358 if ((dirp = opendir(mandir)) == 0) {
359 warn("can't open %s", mandir); 359 warn("can't open %s", mandir);
360 return; 360 return;
361 } 361 }
362 362
363 if (stat(catdir, &catstat) < 0) { 363 if (stat(catdir, &catstat) < 0) {
@@ -560,27 +560,27 @@ setcatsuffix(char *catpage, const char * @@ -560,27 +560,27 @@ setcatsuffix(char *catpage, const char *
560 TAILQ_FIRST(&tp->entrylist)->s, crunchsuff); 560 TAILQ_FIRST(&tp->entrylist)->s, crunchsuff);
561 } else { 561 } else {
562 sprintf(p, ".0%s", crunchsuff); 562 sprintf(p, ".0%s", crunchsuff);
563 } 563 }
564 break; 564 break;
565 } 565 }
566} 566}
567 567
568static void 568static void
569makecat(const char *manpage, const char *catpage, const char *buildcmd,  569makecat(const char *manpage, const char *catpage, const char *buildcmd,
570 const char *crunchcmd) 570 const char *crunchcmd)
571{ 571{
572 char crunchbuf[1024]; 572 char crunchbuf[1024];
573 char sysbuf[2048]; 573 char sysbuf[2048 + 128];
574 size_t len; 574 size_t len;
575 575
576 len = snprintf(sysbuf, sizeof(sysbuf), buildcmd, manpage); 576 len = snprintf(sysbuf, sizeof(sysbuf), buildcmd, manpage);
577 if (len > sizeof(sysbuf)) 577 if (len > sizeof(sysbuf))
578 errx(1, "snprintf"); 578 errx(1, "snprintf");
579 579
580 if (*crunchcmd != '\0') { 580 if (*crunchcmd != '\0') {
581 snprintf(crunchbuf, sizeof(crunchbuf), crunchcmd, catpage); 581 snprintf(crunchbuf, sizeof(crunchbuf), crunchcmd, catpage);
582 snprintf(sysbuf + len, sizeof(sysbuf) - len, " | %s",  582 snprintf(sysbuf + len, sizeof(sysbuf) - len, " | %s",
583 crunchbuf); 583 crunchbuf);
584 } else { 584 } else {
585 snprintf(sysbuf + len, sizeof(sysbuf) - len, " > %s", catpage); 585 snprintf(sysbuf + len, sizeof(sysbuf) - len, " > %s", catpage);
586 } 586 }