Module Name: src
Committed By: christos
Date: Thu Jul 18 15:39:08 UTC 2013
Modified Files:
src/usr.bin/man: Makefile man.c manconf.c
Log Message:
WARNS=6
- fix cast qual issues
- don't use snprintf on a user-provided buffer
To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/man/Makefile
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/man/man.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/man/manconf.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.bin/man/Makefile
diff -u src/usr.bin/man/Makefile:1.11 src/usr.bin/man/Makefile:1.12
--- src/usr.bin/man/Makefile:1.11 Tue Apr 14 18:15:23 2009
+++ src/usr.bin/man/Makefile Thu Jul 18 11:39:08 2013
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.11 2009/04/14 22:15:23 lukem Exp $
+# $NetBSD: Makefile,v 1.12 2013/07/18 15:39:08 christos Exp $
# @(#)Makefile 8.1 (Berkeley) 6/6/93
-WARNS?= 2 # XXX -Wcast-qual issues
+WARNS?= 6
PROG= man
SRCS= man.c manconf.c
Index: src/usr.bin/man/man.c
diff -u src/usr.bin/man/man.c:1.47 src/usr.bin/man/man.c:1.48
--- src/usr.bin/man/man.c:1.47 Thu Jul 18 00:05:32 2013
+++ src/usr.bin/man/man.c Thu Jul 18 11:39:08 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: man.c,v 1.47 2013/07/18 04:05:32 uwe Exp $ */
+/* $NetBSD: man.c,v 1.48 2013/07/18 15:39:08 christos Exp $ */
/*
* Copyright (c) 1987, 1993, 1994, 1995
@@ -40,7 +40,7 @@ __COPYRIGHT("@(#) Copyright (c) 1987, 19
#if 0
static char sccsid[] = "@(#)man.c 8.17 (Berkeley) 1/31/95";
#else
-__RCSID("$NetBSD: man.c,v 1.47 2013/07/18 04:05:32 uwe Exp $");
+__RCSID("$NetBSD: man.c,v 1.48 2013/07/18 15:39:08 christos Exp $");
#endif
#endif /* not lint */
@@ -114,7 +114,7 @@ static void cat(char *);
static const char *check_pager(const char *);
static int cleanup(void);
static void how(char *);
-static void jump(char **, char *, char *);
+static void jump(char **, const char *, const char *);
static int manual(char *, struct manstate *, glob_t *);
static void onsig(int);
static void usage(void) __attribute__((__noreturn__));
@@ -122,13 +122,15 @@ static void addpath(struct manstate *,
static const char *getclass(const char *);
static void printmanpath(struct manstate *);
+static char EMPTY[1];
+
/*
* main function
*/
int
main(int argc, char **argv)
{
- static struct manstate m = { 0 }; /* init to zero */
+ static struct manstate m;
int ch, abs_section, found;
ENTRY *esubd, *epath;
char *p, **ap, *cmd;
@@ -464,6 +466,21 @@ main(int argc, char **argv)
exit(cleanup());
}
+static void
+fixstring(char *buf, size_t len, const char *fmt, const char *str)
+{
+ const char *ptr = strstr(fmt, "%s");
+ size_t l;
+ if (ptr == NULL) {
+ strlcpy(buf, fmt, len);
+ return;
+ }
+ l = (size_t)(ptr - fmt) + 1;
+ strlcpy(buf, fmt, MIN(l, len));
+ strlcat(buf, str, len);
+ strlcat(buf, ptr + 2, len);
+}
+
static int
manual_find_buildkeyword(char *escpage, const char *fmt,
struct manstate *mp, glob_t *pg, size_t cnt)
@@ -483,7 +500,7 @@ manual_find_buildkeyword(char *escpage,
continue;
*p = '\0';
- (void)snprintf(buf, sizeof(buf), fmt, escpage, suffix->s);
+ fixstring(buf, sizeof(buf), fmt, escpage);
if (!fnmatch(buf, pg->gl_pathv[cnt], 0)) {
if (!mp->where)
build_page(p + 1, &pg->gl_pathv[cnt], mp);
@@ -570,14 +587,14 @@ manual(char *page, struct manstate *mp,
if (!mp->all) {
/* Delete any other matches. */
while (++cnt< pg->gl_pathc)
- pg->gl_pathv[cnt] = "";
+ pg->gl_pathv[cnt] = EMPTY;
break;
}
continue;
}
/* It's not a man page, forget about it. */
- pg->gl_pathv[cnt] = "";
+ pg->gl_pathv[cnt] = EMPTY;
}
notfound:
@@ -626,7 +643,7 @@ manual(char *page, struct manstate *mp,
if (mp->pathsearch) {
p = strstr(pg->gl_pathv[cnt], mp->pathsearch);
if (!p || strchr(p, '/') == NULL) {
- pg->gl_pathv[cnt] = ""; /* zap! */
+ pg->gl_pathv[cnt] = EMPTY; /* zap! */
continue;
}
}
@@ -665,14 +682,14 @@ next: anyfound = 1;
if (!mp->all) {
/* Delete any other matches. */
while (++cnt< pg->gl_pathc)
- pg->gl_pathv[cnt] = "";
+ pg->gl_pathv[cnt] = EMPTY;
break;
}
continue;
}
/* It's not a man page, forget about it. */
- pg->gl_pathv[cnt] = "";
+ pg->gl_pathv[cnt] = EMPTY;
}
if (anyfound && !mp->all)
@@ -700,7 +717,8 @@ static void
build_page(char *fmt, char **pathp, struct manstate *mp)
{
static int warned;
- int olddir, fd, n, tmpdirlen;
+ int olddir, fd, n;
+ size_t tmpdirlen;
char *p, *b;
char buf[MAXPATHLEN], cmd[MAXPATHLEN], tpath[MAXPATHLEN];
const char *tmpdir;
@@ -765,7 +783,7 @@ build_page(char *fmt, char **pathp, stru
exit(EXIT_FAILURE);
}
(void)snprintf(buf, sizeof(buf), "%s > %s", fmt, tpath);
- (void)snprintf(cmd, sizeof(cmd), buf, p);
+ fixstring(cmd, sizeof(cmd), buf, p);
(void)system(cmd);
(void)close(fd);
if ((*pathp = strdup(tpath)) == NULL) {
@@ -842,7 +860,8 @@ how(char *fname)
static void
cat(char *fname)
{
- int fd, n;
+ int fd;
+ ssize_t n;
char buf[2048];
if ((fd = open(fname, O_RDONLY, 0)) < 0) {
@@ -851,7 +870,7 @@ cat(char *fname)
exit(EXIT_FAILURE);
}
while ((n = read(fd, buf, sizeof(buf))) > 0)
- if (write(STDOUT_FILENO, buf, n) != n) {
+ if (write(STDOUT_FILENO, buf, (size_t)n) != n) {
warn("write");
(void)cleanup();
exit(EXIT_FAILURE);
@@ -898,11 +917,11 @@ check_pager(const char *name)
* strip out flag argument and jump
*/
static void
-jump(char **argv, char *flag, char *name)
+jump(char **argv, const char *flag, const char *name)
{
char **arg;
- argv[0] = name;
+ argv[0] = __UNCONST(name);
for (arg = argv + 1; *arg; ++arg)
if (!strcmp(*arg, flag))
break;
Index: src/usr.bin/man/manconf.c
diff -u src/usr.bin/man/manconf.c:1.6 src/usr.bin/man/manconf.c:1.7
--- src/usr.bin/man/manconf.c:1.6 Sat Mar 8 10:48:27 2008
+++ src/usr.bin/man/manconf.c Thu Jul 18 11:39:08 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: manconf.c,v 1.6 2008/03/08 15:48:27 christos Exp $ */
+/* $NetBSD: manconf.c,v 1.7 2013/07/18 15:39:08 christos Exp $ */
/*
* Copyright (c) 1989, 1993, 1995
@@ -45,7 +45,7 @@
#if 0
static char sccsid[] = "@(#)config.c 8.8 (Berkeley) 1/31/95";
#else
-__RCSID("$NetBSD: manconf.c,v 1.6 2008/03/08 15:48:27 christos Exp $");
+__RCSID("$NetBSD: manconf.c,v 1.7 2013/07/18 15:39:08 christos Exp $");
#endif
#endif /* not lint */
@@ -172,8 +172,8 @@ config(const char *fname)
* section entries can either be all absolute
* paths or all relative paths, but not both.
*/
- type = (TAILQ_FIRST(&tp->entrylist) != NULL) ?
- *(TAILQ_FIRST(&tp->entrylist)->s) : 0;
+ type = (char)((TAILQ_FIRST(&tp->entrylist) != NULL) ?
+ *(TAILQ_FIRST(&tp->entrylist)->s) : '\0');
for (++t; (p = strtok(t, " \t\n")) != NULL; t = NULL) {