use bounded string op as much as possible

This commit is contained in:
itojun 2003-07-14 06:17:54 +00:00
parent 5402d14cf4
commit 49a751869e
7 changed files with 32 additions and 31 deletions

View File

@ -1,11 +1,11 @@
/* $NetBSD: main.c,v 1.29 2003/06/05 13:15:43 agc Exp $ */ /* $NetBSD: main.c,v 1.30 2003/07/14 06:17:54 itojun Exp $ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
#if 0 #if 0
static char *rcsid = "from FreeBSD Id: main.c,v 1.16 1997/10/08 07:45:43 charnier Exp"; static char *rcsid = "from FreeBSD Id: main.c,v 1.16 1997/10/08 07:45:43 charnier Exp";
#else #else
__RCSID("$NetBSD: main.c,v 1.29 2003/06/05 13:15:43 agc Exp $"); __RCSID("$NetBSD: main.c,v 1.30 2003/07/14 06:17:54 itojun Exp $");
#endif #endif
#endif #endif
@ -102,7 +102,7 @@ main(int argc, char **argv)
break; break;
case 't': case 't':
strcpy(FirstPen, optarg); strlcpy(FirstPen, optarg, sizeof(FirstPen));
break; break;
case 'S': case 'S':

View File

@ -1,11 +1,11 @@
/* $NetBSD: main.c,v 1.24 2003/06/05 13:15:44 agc Exp $ */ /* $NetBSD: main.c,v 1.25 2003/07/14 06:17:55 itojun Exp $ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
#if 0 #if 0
static const char *rcsid = "from FreeBSD Id: main.c,v 1.17 1997/10/08 07:46:23 charnier Exp"; static const char *rcsid = "from FreeBSD Id: main.c,v 1.17 1997/10/08 07:46:23 charnier Exp";
#else #else
__RCSID("$NetBSD: main.c,v 1.24 2003/06/05 13:15:44 agc Exp $"); __RCSID("$NetBSD: main.c,v 1.25 2003/07/14 06:17:55 itojun Exp $");
#endif #endif
#endif #endif
@ -142,7 +142,7 @@ main(int argc, char **argv)
break; break;
case 't': case 't':
strcpy(PlayPen, optarg); strlcpy(PlayPen, optarg, sizeof(PlayPen));
break; break;
case 'X': case 'X':

View File

@ -1,11 +1,11 @@
/* $NetBSD: pl.c,v 1.26 2003/06/12 13:29:32 agc Exp $ */ /* $NetBSD: pl.c,v 1.27 2003/07/14 06:17:55 itojun Exp $ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
#if 0 #if 0
static const char *rcsid = "from FreeBSD Id: pl.c,v 1.11 1997/10/08 07:46:35 charnier Exp"; static const char *rcsid = "from FreeBSD Id: pl.c,v 1.11 1997/10/08 07:46:35 charnier Exp";
#else #else
__RCSID("$NetBSD: pl.c,v 1.26 2003/06/12 13:29:32 agc Exp $"); __RCSID("$NetBSD: pl.c,v 1.27 2003/07/14 06:17:55 itojun Exp $");
#endif #endif
#endif #endif
@ -201,7 +201,8 @@ check_list(char *home, package_t *pkg, const char *PkgName)
warnx("Warning - block special device `%s' in PLIST", name); warnx("Warning - block special device `%s' in PLIST", name);
break; break;
default: default:
(void) strcpy(buf, CHECKSUM_HEADER); (void) strlcpy(buf, CHECKSUM_HEADER,
sizeof(buf));
if (MD5File(name, &buf[ChecksumHeaderLen]) != (char *) NULL) { if (MD5File(name, &buf[ChecksumHeaderLen]) != (char *) NULL) {
tmp = new_plist_entry(); tmp = new_plist_entry();
tmp->name = strdup(buf); tmp->name = strdup(buf);

View File

@ -1,11 +1,11 @@
/* $NetBSD: perform.c,v 1.45 2003/03/24 21:44:46 seb Exp $ */ /* $NetBSD: perform.c,v 1.46 2003/07/14 06:17:55 itojun Exp $ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
#if 0 #if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.23 1997/10/13 15:03:53 jkh Exp"; static const char *rcsid = "from FreeBSD Id: perform.c,v 1.23 1997/10/13 15:03:53 jkh Exp";
#else #else
__RCSID("$NetBSD: perform.c,v 1.45 2003/03/24 21:44:46 seb Exp $"); __RCSID("$NetBSD: perform.c,v 1.46 2003/07/14 06:17:55 itojun Exp $");
#endif #endif
#endif #endif
@ -54,7 +54,7 @@ pkg_do(char *pkg)
if (IS_URL(pkg)) { if (IS_URL(pkg)) {
if ((cp = fileGetURL(pkg)) != NULL) { if ((cp = fileGetURL(pkg)) != NULL) {
strcpy(fname, cp); strlcpy(fname, cp, sizeof(fname));
isTMP = TRUE; isTMP = TRUE;
} }
} else if (fexists(pkg) && isfile(pkg)) { } else if (fexists(pkg) && isfile(pkg)) {
@ -68,7 +68,7 @@ pkg_do(char *pkg)
len = strlen(fname); len = strlen(fname);
(void) snprintf(&fname[len], sizeof(fname) - len, "/%s", pkg); (void) snprintf(&fname[len], sizeof(fname) - len, "/%s", pkg);
} else { } else {
strcpy(fname, pkg); strlcpy(fname, pkg, sizeof(fname));
} }
cp = fname; cp = fname;
} else { } else {
@ -89,7 +89,7 @@ pkg_do(char *pkg)
char *cp2; char *cp2;
if ((cp2 = fileGetURL(cp)) != NULL) { if ((cp2 = fileGetURL(cp)) != NULL) {
strcpy(fname, cp2); strlcpy(fname, cp2, sizeof(fname));
isTMP = TRUE; isTMP = TRUE;
} }
strcpy(PlayPen, cp2); strcpy(PlayPen, cp2);

View File

@ -1,8 +1,8 @@
/* $NetBSD: ftpio.c,v 1.51 2003/06/23 16:46:57 tacha Exp $ */ /* $NetBSD: ftpio.c,v 1.52 2003/07/14 06:17:56 itojun Exp $ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
__RCSID("$NetBSD: ftpio.c,v 1.51 2003/06/23 16:46:57 tacha Exp $"); __RCSID("$NetBSD: ftpio.c,v 1.52 2003/07/14 06:17:56 itojun Exp $");
#endif #endif
/* /*
@ -548,7 +548,7 @@ expandURL(char *expandedurl, const char *wildcardurl)
char best[FILENAME_MAX]; char best[FILENAME_MAX];
int tfd; int tfd;
strcpy(tmpname, "/var/tmp/pkg.XXXXXX"); strlcpy(tmpname, "/var/tmp/pkg.XXXXXX", sizeof(tmpname));
tfd=mkstemp(tmpname); tfd=mkstemp(tmpname);
if (tfd == -1) { if (tfd == -1) {
warnx("Cannot generate temp file for ftp(1)'s nlist output"); warnx("Cannot generate temp file for ftp(1)'s nlist output");

View File

@ -1,11 +1,11 @@
/* $NetBSD: pen.c,v 1.26 2003/04/10 23:38:16 grant Exp $ */ /* $NetBSD: pen.c,v 1.27 2003/07/14 06:17:56 itojun Exp $ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
#if 0 #if 0
static const char *rcsid = "from FreeBSD Id: pen.c,v 1.25 1997/10/08 07:48:12 charnier Exp"; static const char *rcsid = "from FreeBSD Id: pen.c,v 1.25 1997/10/08 07:48:12 charnier Exp";
#else #else
__RCSID("$NetBSD: pen.c,v 1.26 2003/04/10 23:38:16 grant Exp $"); __RCSID("$NetBSD: pen.c,v 1.27 2003/07/14 06:17:56 itojun Exp $");
#endif #endif
#endif #endif
@ -65,11 +65,11 @@ void
restore_dirs(char *c, char *p) restore_dirs(char *c, char *p)
{ {
CurrentSet = 0; /* prevent from deleting */ CurrentSet = 0; /* prevent from deleting */
strcpy(Current, c); strlcpy(Current, c, sizeof(Current));
CurrentSet = 1; /* rm -fr Current is safe now */ CurrentSet = 1; /* rm -fr Current is safe now */
free(c); free(c);
strcpy(Previous, p); strlcpy(Previous, p, sizeof(Previous));
free(p); free(p);
} }
#endif #endif
@ -96,11 +96,11 @@ find_play_pen(char *pen, size_t pensize, size_t sz)
else if ((cp = getenv("TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz)) else if ((cp = getenv("TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz))
(void) snprintf(pen, pensize, "%s/instmp.XXXXXX", cp); (void) snprintf(pen, pensize, "%s/instmp.XXXXXX", cp);
else if (stat("/var/tmp", &sb) != FAIL && min_free("/var/tmp") >= sz) else if (stat("/var/tmp", &sb) != FAIL && min_free("/var/tmp") >= sz)
strcpy(pen, "/var/tmp/instmp.XXXXXX"); strlcpy(pen, "/var/tmp/instmp.XXXXXX", pensize);
else if (stat("/tmp", &sb) != FAIL && min_free("/tmp") >= sz) else if (stat("/tmp", &sb) != FAIL && min_free("/tmp") >= sz)
strcpy(pen, "/tmp/instmp.XXXXXX"); strlcpy(pen, "/tmp/instmp.XXXXXX", pensize);
else if (stat("/usr/tmp", &sb) != FAIL && min_free("/usr/tmp") >= sz) else if (stat("/usr/tmp", &sb) != FAIL && min_free("/usr/tmp") >= sz)
strcpy(pen, "/usr/tmp/instmp.XXXXXX"); strlcpy(pen, "/usr/tmp/instmp.XXXXXX", pensize);
else { else {
cleanup(0); cleanup(0);
errx(2, errx(2,
@ -153,7 +153,7 @@ make_playpen(char *pen, size_t pensize, size_t sz)
"with more space and\ntry the command again", pen); "with more space and\ntry the command again", pen);
} }
if (Current[0]) if (Current[0])
strcpy(Previous, Current); strlcpy(Previous, Current, sizeof(Previous));
else if (!getcwd(Previous, FILENAME_MAX)) { else if (!getcwd(Previous, FILENAME_MAX)) {
cleanup(0); cleanup(0);
err(EXIT_FAILURE, "fatal error during execution: getcwd"); err(EXIT_FAILURE, "fatal error during execution: getcwd");
@ -162,7 +162,7 @@ make_playpen(char *pen, size_t pensize, size_t sz)
cleanup(0); cleanup(0);
errx(2, "can't chdir to '%s'", pen); errx(2, "can't chdir to '%s'", pen);
} }
CurrentSet = 0; strcpy(Current, pen); CurrentSet = 1; CurrentSet = 0; strlcpy(Current, pen, sizeof(Current)); CurrentSet = 1;
return Previous; return Previous;
} }
@ -187,10 +187,10 @@ leave_playpen(char *save)
} }
if (vsystem("rm -rf %s", Current)) if (vsystem("rm -rf %s", Current))
warnx("couldn't remove temporary dir '%s'", Current); warnx("couldn't remove temporary dir '%s'", Current);
strcpy(Current, Previous); strlcpy(Current, Previous, sizeof(Current));
} }
if (save) if (save)
strcpy(Previous, save); strlcpy(Previous, save, sizeof(Previous));
else else
Previous[0] = '\0'; Previous[0] = '\0';
signal(SIGINT, oldsig); signal(SIGINT, oldsig);

View File

@ -1,11 +1,11 @@
/* $NetBSD: plist.c,v 1.38 2003/04/14 23:42:21 grant Exp $ */ /* $NetBSD: plist.c,v 1.39 2003/07/14 06:17:56 itojun Exp $ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
#if 0 #if 0
static const char *rcsid = "from FreeBSD Id: plist.c,v 1.24 1997/10/08 07:48:15 charnier Exp"; static const char *rcsid = "from FreeBSD Id: plist.c,v 1.24 1997/10/08 07:48:15 charnier Exp";
#else #else
__RCSID("$NetBSD: plist.c,v 1.38 2003/04/14 23:42:21 grant Exp $"); __RCSID("$NetBSD: plist.c,v 1.39 2003/07/14 06:17:56 itojun Exp $");
#endif #endif
#endif #endif
@ -235,7 +235,7 @@ plist_cmd(char *s, char **arg)
char *cp; char *cp;
char *sp; char *sp;
(void) strcpy(cmd, s); (void) strlcpy(cmd, s, sizeof(cmd));
str_lowercase(cmd); str_lowercase(cmd);
for (cp = cmd, sp = s; *cp; cp++, sp++) { for (cp = cmd, sp = s; *cp; cp++, sp++) {
if (isspace((unsigned char) *cp)) { if (isspace((unsigned char) *cp)) {