summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2003-04-06 22:47:15 +0000
committerMarc Espie <espie@cvs.openbsd.org>2003-04-06 22:47:15 +0000
commit480e6f4b66ecde3ac8804e0d92e2fa768097af96 (patch)
tree939212e570e52fbb01c840b68150b5251f298b7b
parent8c9ed37797045721315b3fcc5542502fbea40420 (diff)
get rid of some strcpy/sprintf.
ok krw@, matthieu@, deraadt@
-rw-r--r--usr.bin/make/arch.c13
-rw-r--r--usr.bin/make/job.c8
-rw-r--r--usr.bin/make/main.c8
-rw-r--r--usr.bin/make/util.c16
4 files changed, 25 insertions, 20 deletions
diff --git a/usr.bin/make/arch.c b/usr.bin/make/arch.c
index 77bfe6f2ac6..ebbbf784b1a 100644
--- a/usr.bin/make/arch.c
+++ b/usr.bin/make/arch.c
@@ -1,5 +1,5 @@
/* $OpenPackages$ */
-/* $OpenBSD: arch.c,v 1.51 2002/01/30 18:40:26 matthieu Exp $ */
+/* $OpenBSD: arch.c,v 1.52 2003/04/06 22:47:14 espie Exp $ */
/* $NetBSD: arch.c,v 1.17 1996/11/06 17:58:59 christos Exp $ */
/*
@@ -313,15 +313,17 @@ Arch_ParseArchive(linePtr, nodeLst, ctxt)
char *buf;
char *sacrifice;
char *oldMemName = memName;
+ size_t len;
memName = Var_Subst(memName, ctxt, true);
/* Now form an archive spec and recurse to deal with nested
* variables and multi-word variable values.... The results
* are just placed at the end of the nodeLst we're returning. */
- buf = sacrifice = emalloc(strlen(memName)+strlen(libName)+3);
+ len = strlen(memName)+strlen(libName)+3;
+ buf = sacrifice = emalloc(len);
- sprintf(buf, "%s(%s)", libName, memName);
+ snprintf(buf, len, "%s(%s)", libName, memName);
if (strchr(memName, '$') && strcmp(memName, oldMemName) == 0) {
/* Must contain dynamic sources, so we can't deal with it now.
@@ -974,9 +976,10 @@ Arch_FindLib(gn, path)
Lst path; /* Search path */
{
char *libName; /* file name for archive */
+ size_t len = strlen(gn->name) + 6 - 2;
- libName = emalloc(strlen(gn->name) + 6 - 2);
- sprintf(libName, "lib%s.a", &gn->name[2]);
+ libName = emalloc(len);
+ snprintf(libName, len, "lib%s.a", &gn->name[2]);
gn->path = Dir_FindFile(libName, path);
diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c
index 29a9fe37b7d..7d8382d1ae3 100644
--- a/usr.bin/make/job.c
+++ b/usr.bin/make/job.c
@@ -1,5 +1,5 @@
/* $OpenPackages$ */
-/* $OpenBSD: job.c,v 1.53 2003/02/18 13:14:43 jmc Exp $ */
+/* $OpenBSD: job.c,v 1.54 2003/04/06 22:47:14 espie Exp $ */
/* $NetBSD: job.c,v 1.16 1996/11/06 17:59:08 christos Exp $ */
/*
@@ -1349,7 +1349,7 @@ JobMakeArgv(job, argv)
* Bourne shell thinks its second argument is a file to source.
* Grrrr. Note the ten-character limitation on the combined arguments.
*/
- (void)sprintf(args, "-%s%s",
+ (void)snprintf(args, sizeof(args), "-%s%s",
((job->flags & JOB_IGNERR) ? "" :
(commandShell->exit ? commandShell->exit : "")),
((job->flags & JOB_SILENT) ? "" :
@@ -1731,7 +1731,7 @@ JobStart(gn, flags, previous)
} else {
(void)fprintf(stdout, "Remaking `%s'\n", gn->name);
(void)fflush(stdout);
- (void)strcpy(job->outFile, TMPPAT);
+ (void)strlcpy(job->outFile, TMPPAT, sizeof(job->outFile));
if ((job->outFd = mkstemp(job->outFile)) == -1)
Punt("Cannot create temp file: %s", strerror(errno));
(void)fcntl(job->outFd, F_SETFD, 1);
@@ -2182,7 +2182,7 @@ Job_Init(maxproc, maxlocal)
GNode *begin; /* node for commands to do at the very start */
int tfd;
- (void)strcpy(tfile, TMPPAT);
+ (void)strlcpy(tfile, TMPPAT, sizeof(tfile));
if ((tfd = mkstemp(tfile)) == -1)
Punt("Cannot create temp file: %s", strerror(errno));
else
diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c
index 8e288b22f6d..c136e082e7f 100644
--- a/usr.bin/make/main.c
+++ b/usr.bin/make/main.c
@@ -1,5 +1,5 @@
/* $OpenPackages$ */
-/* $OpenBSD: main.c,v 1.59 2002/12/30 22:12:38 millert Exp $ */
+/* $OpenBSD: main.c,v 1.60 2003/04/06 22:47:14 espie Exp $ */
/* $NetBSD: main.c,v 1.34 1997/03/24 20:56:36 gwr Exp $ */
/*
@@ -346,6 +346,7 @@ Main_ParseArgLine(line)
char *buf;
char *argv0;
const char *s;
+ size_t len;
if (line == NULL)
@@ -367,8 +368,9 @@ Main_ParseArgLine(line)
break;
}
argv0 = Var_Value(".MAKE");
- buf = emalloc(strlen(line) + strlen(argv0) + 2);
- (void)sprintf(buf, "%s %s", argv0, line);
+ len = strlen(line) + strlen(argv0) + 2;
+ buf = emalloc(len);
+ (void)snprintf(buf, len, "%s %s", argv0, line);
argv = brk_string(buf, &argc, &args);
free(buf);
diff --git a/usr.bin/make/util.c b/usr.bin/make/util.c
index 0a82f579b5a..b3aa794341f 100644
--- a/usr.bin/make/util.c
+++ b/usr.bin/make/util.c
@@ -1,5 +1,5 @@
/* $OpenPackages$ */
-/* $OpenBSD: util.c,v 1.18 2002/05/29 09:23:25 deraadt Exp $ */
+/* $OpenBSD: util.c,v 1.19 2003/04/06 22:47:14 espie Exp $ */
/* $NetBSD: util.c,v 1.10 1996/12/31 17:56:04 christos Exp $ */
/*
@@ -207,7 +207,7 @@ getwd(pathname)
/* find the inode of root */
if (stat("/", &st_root) == -1) {
- (void)sprintf(pathname,
+ (void)snprintf(pathname, MAXPATHLEN,
"getwd: Cannot stat \"/\" (%s)", strerror(errno));
return NULL;
}
@@ -218,7 +218,7 @@ getwd(pathname)
/* find the inode of the current directory */
if (lstat(".", &st_cur) == -1) {
- (void)sprintf(pathname,
+ (void)snprintf(pathname, MAXPATHLEN,
"getwd: Cannot stat \".\" (%s)", strerror(errno));
return NULL;
}
@@ -230,19 +230,19 @@ getwd(pathname)
/* look if we found root yet */
if (st_cur.st_ino == st_root.st_ino &&
DEV_DEV_COMPARE(st_cur.st_dev, st_root.st_dev)) {
- (void)strcpy(pathname, *pathptr != '/' ? "/" : pathptr);
+ (void)strlcpy(pathname, *pathptr != '/' ? "/" : pathptr, MAXPATHLEN);
return pathname;
}
/* open the parent directory */
if (stat(nextpathptr, &st_dotdot) == -1) {
- (void)sprintf(pathname,
+ (void)snprintf(pathname, MAXPATHLEN,
"getwd: Cannot stat directory \"%s\" (%s)",
nextpathptr, strerror(errno));
return NULL;
}
if ((dp = opendir(nextpathptr)) == NULL) {
- (void)sprintf(pathname,
+ (void)snprintf(pathname, MAXPATHLEN,
"getwd: Cannot open directory \"%s\" (%s)",
nextpathptr, strerror(errno));
return NULL;
@@ -265,7 +265,7 @@ getwd(pathname)
continue;
(void)strcpy(cur_name_add, d->d_name);
if (lstat(nextpathptr, &st_next) == -1) {
- (void)sprintf(pathname,
+ (void)snprintf(pathname, MAXPATHLEN,
"getwd: Cannot stat \"%s\" (%s)",
d->d_name, strerror(errno));
(void)closedir(dp);
@@ -278,7 +278,7 @@ getwd(pathname)
}
}
if (d == NULL) {
- (void)sprintf(pathname,
+ (void)snprintf(pathname, MAXPATHLEN,
"getwd: Cannot find \".\" in \"..\"");
(void)closedir(dp);
return NULL;