summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2003-04-05 17:17:53 +0000
committerderaadt <deraadt@openbsd.org>2003-04-05 17:17:53 +0000
commit1f7e104bfc8b45091d63639f00b06131ee5e7ef1 (patch)
treedb54e30a1e93e2f3130877092c72886188a4f267
parentsnprintf; ok miod ho henning (diff)
downloadwireguard-openbsd-1f7e104bfc8b45091d63639f00b06131ee5e7ef1.tar.xz
wireguard-openbsd-1f7e104bfc8b45091d63639f00b06131ee5e7ef1.zip
string fixes; ok miod henning
-rw-r--r--usr.bin/ftp/cmds.c9
-rw-r--r--usr.bin/ftp/complete.c8
-rw-r--r--usr.bin/ftp/fetch.c6
-rw-r--r--usr.bin/ftp/ftp.c14
-rw-r--r--usr.bin/ftp/main.c6
-rw-r--r--usr.bin/ftp/ruserpass.c26
-rw-r--r--usr.bin/ftp/util.c25
-rw-r--r--usr.bin/patch/backupfile.c16
-rw-r--r--usr.bin/patch/patch.c26
-rw-r--r--usr.bin/patch/pch.c20
-rw-r--r--usr.bin/patch/util.c6
11 files changed, 73 insertions, 89 deletions
diff --git a/usr.bin/ftp/cmds.c b/usr.bin/ftp/cmds.c
index 8b20f0971c4..87889eb1593 100644
--- a/usr.bin/ftp/cmds.c
+++ b/usr.bin/ftp/cmds.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmds.c,v 1.43 2003/03/31 23:04:07 millert Exp $ */
+/* $OpenBSD: cmds.c,v 1.44 2003/04/05 17:19:47 deraadt Exp $ */
/* $NetBSD: cmds.c,v 1.27 1997/08/18 10:20:15 lukem Exp $ */
/*
@@ -67,7 +67,7 @@
#if 0
static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
#else
-static char rcsid[] = "$OpenBSD: cmds.c,v 1.43 2003/03/31 23:04:07 millert Exp $";
+static char rcsid[] = "$OpenBSD: cmds.c,v 1.44 2003/04/05 17:19:47 deraadt Exp $";
#endif
#endif /* not lint */
@@ -152,7 +152,7 @@ settype(argc, argv)
else
comret = command("TYPE %s", p->t_mode);
if (comret == COMPLETE) {
- (void)strcpy(typename, p->t_name);
+ (void)strlcpy(typename, p->t_name, sizeof typename);
curtype = type = p->t_type;
}
}
@@ -2242,9 +2242,8 @@ page(argc, argv)
p = getenv("PAGER");
if (p == NULL || (*p == '\0'))
p = PAGER;
- if ((pager = malloc(strlen(p) + 2)) == NULL)
+ if (asprintf(&pager, "|%s", p) == -1)
errx(1, "Can't allocate memory for $PAGER");
- (void)sprintf(pager, "|%s", p);
orestart_point = restart_point;
ohash = hash;
diff --git a/usr.bin/ftp/complete.c b/usr.bin/ftp/complete.c
index d10ad9a4dfa..9c030d51a99 100644
--- a/usr.bin/ftp/complete.c
+++ b/usr.bin/ftp/complete.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: complete.c,v 1.13 2002/02/16 21:27:46 millert Exp $ */
+/* $OpenBSD: complete.c,v 1.14 2003/04/05 17:19:47 deraadt Exp $ */
/* $NetBSD: complete.c,v 1.10 1997/08/18 10:20:18 lukem Exp $ */
/*-
@@ -39,7 +39,7 @@
#ifndef SMALL
#ifndef lint
-static char rcsid[] = "$OpenBSD: complete.c,v 1.13 2002/02/16 21:27:46 millert Exp $";
+static char rcsid[] = "$OpenBSD: complete.c,v 1.14 2003/04/05 17:19:47 deraadt Exp $";
#endif /* not lint */
/*
@@ -94,7 +94,7 @@ complete_ambiguous(word, list, words)
return (CC_ERROR); /* no choices available */
if (words->sl_cur == 1) { /* only once choice available */
- (void)strcpy(insertstr, words->sl_str[0]);
+ (void)strlcpy(insertstr, words->sl_str[0], sizeof insertstr);
if (el_insertstr(el, insertstr + wordlen) == -1)
return (CC_ERROR);
else
@@ -277,7 +277,7 @@ complete_remote(word, list)
fprintf(ttyout, "\n%s\n", emesg);
return (CC_REDISPLAY);
}
- (void)strcpy(lastdir, dir);
+ (void)strlcpy(lastdir, dir, sizeof lastdir);
dirchange = 0;
}
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c
index 62a97c948d9..d988fc2e13d 100644
--- a/usr.bin/ftp/fetch.c
+++ b/usr.bin/ftp/fetch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fetch.c,v 1.45 2003/03/31 23:04:07 millert Exp $ */
+/* $OpenBSD: fetch.c,v 1.46 2003/04/05 17:19:47 deraadt Exp $ */
/* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */
/*-
@@ -38,7 +38,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: fetch.c,v 1.45 2003/03/31 23:04:07 millert Exp $";
+static char rcsid[] = "$OpenBSD: fetch.c,v 1.46 2003/04/05 17:19:47 deraadt Exp $";
#endif /* not lint */
/*
@@ -783,7 +783,7 @@ bad_ftp_url:
if (strcmp(host, lasthost) != 0) {
int oautologin;
- (void)strcpy(lasthost, host);
+ (void)strlcpy(lasthost, host, sizeof lasthost);
if (connected)
disconnect(0, NULL);
xargv[0] = __progname;
diff --git a/usr.bin/ftp/ftp.c b/usr.bin/ftp/ftp.c
index d5273169d22..3ec77dcec6b 100644
--- a/usr.bin/ftp/ftp.c
+++ b/usr.bin/ftp/ftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ftp.c,v 1.51 2003/03/11 04:01:29 itojun Exp $ */
+/* $OpenBSD: ftp.c,v 1.52 2003/04/05 17:19:47 deraadt Exp $ */
/* $NetBSD: ftp.c,v 1.27 1997/08/18 10:20:23 lukem Exp $ */
/*
@@ -67,7 +67,7 @@
#if 0
static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
#else
-static char rcsid[] = "$OpenBSD: ftp.c,v 1.51 2003/03/11 04:01:29 itojun Exp $";
+static char rcsid[] = "$OpenBSD: ftp.c,v 1.52 2003/04/05 17:19:47 deraadt Exp $";
#endif
#endif /* not lint */
@@ -1663,15 +1663,15 @@ pswitch(flag)
ip->ntflg = ntflag;
ntflag = op->ntflg;
(void)strlcpy(ip->nti, ntin, sizeof(ip->nti));
- (void)strcpy(ntin, op->nti);
+ (void)strlcpy(ntin, op->nti, sizeof ntin);
(void)strlcpy(ip->nto, ntout, sizeof(ip->nto));
- (void)strcpy(ntout, op->nto);
+ (void)strlcpy(ntout, op->nto, sizeof ntout);
ip->mapflg = mapflag;
mapflag = op->mapflg;
(void)strlcpy(ip->mi, mapin, sizeof(ip->mi));
- (void)strcpy(mapin, op->mi);
+ (void)strlcpy(mapin, op->mi, sizeof mapin);
(void)strlcpy(ip->mo, mapout, sizeof(ip->mo));
- (void)strcpy(mapout, op->mo);
+ (void)strlcpy(mapout, op->mo, sizeof mapout);
(void)signal(SIGINT, oldintr);
if (abrtflag) {
abrtflag = 0;
@@ -1856,7 +1856,7 @@ gunique(local)
warn("local: %s", local);
return ((char *) 0);
}
- (void)strcpy(new, local);
+ (void)strlcpy(new, local, sizeof new);
cp = new + strlen(new);
*cp++ = '.';
while (!d) {
diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c
index f37a385fe74..ea1b8a7a4d6 100644
--- a/usr.bin/ftp/main.c
+++ b/usr.bin/ftp/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.51 2003/03/31 23:04:07 millert Exp $ */
+/* $OpenBSD: main.c,v 1.52 2003/04/05 17:19:47 deraadt Exp $ */
/* $NetBSD: main.c,v 1.24 1997/08/18 10:20:26 lukem Exp $ */
/*
@@ -73,7 +73,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
#else
-static char rcsid[] = "$OpenBSD: main.c,v 1.51 2003/03/31 23:04:07 millert Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.52 2003/04/05 17:19:47 deraadt Exp $";
#endif
#endif /* not lint */
@@ -281,8 +281,8 @@ main(argc, argv)
if (pw == NULL)
pw = getpwuid(getuid());
if (pw != NULL) {
+ (void)strlcpy(homedir, pw->pw_dir, sizeof homedir);
home = homedir;
- (void)strcpy(home, pw->pw_dir);
}
setttywidth(0);
diff --git a/usr.bin/ftp/ruserpass.c b/usr.bin/ftp/ruserpass.c
index 0f310f70f0f..39a62df5ce9 100644
--- a/usr.bin/ftp/ruserpass.c
+++ b/usr.bin/ftp/ruserpass.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ruserpass.c,v 1.14 2003/03/31 23:04:07 millert Exp $ */
+/* $OpenBSD: ruserpass.c,v 1.15 2003/04/05 17:19:47 deraadt Exp $ */
/* $NetBSD: ruserpass.c,v 1.14 1997/07/20 09:46:01 lukem Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)ruserpass.c 8.4 (Berkeley) 4/27/95";
#else
-static char rcsid[] = "$OpenBSD: ruserpass.c,v 1.14 2003/03/31 23:04:07 millert Exp $";
+static char rcsid[] = "$OpenBSD: ruserpass.c,v 1.15 2003/04/05 17:19:47 deraadt Exp $";
#endif
#endif /* not lint */
@@ -96,7 +96,7 @@ ruserpass(host, aname, apass, aacct)
if (hdir == NULL || *hdir == '\0')
return (0);
if (strlen(hdir) + sizeof(".netrc") < sizeof(buf)) {
- (void)sprintf(buf, "%s/.netrc", hdir);
+ (void)snprintf(buf, sizeof buf, "%s/.netrc", hdir);
} else {
warnx("%s/.netrc: %s", hdir, strerror(ENAMETOOLONG));
return (0);
@@ -150,11 +150,9 @@ next:
case LOGIN:
if (token()) {
- if (*aname == 0) {
- *aname = malloc((unsigned)
- strlen(tokval) + 1);
- (void)strcpy(*aname, tokval);
- } else {
+ if (*aname == 0)
+ *aname = strdup(tokval);
+ else {
if (strcmp(*aname, tokval))
goto next;
}
@@ -168,10 +166,8 @@ next:
warnx("Remove password or make file unreadable by others.");
goto bad;
}
- if (token() && *apass == 0) {
- *apass = malloc((unsigned) strlen(tokval) + 1);
- (void)strcpy(*apass, tokval);
- }
+ if (token() && *apass == 0)
+ *apass = strdup(tokval);
break;
case ACCOUNT:
if (fstat(fileno(cfile), &stb) >= 0
@@ -180,10 +176,8 @@ next:
warnx("Remove account or make file unreadable by others.");
goto bad;
}
- if (token() && *aacct == 0) {
- *aacct = malloc((unsigned) strlen(tokval) + 1);
- (void)strcpy(*aacct, tokval);
- }
+ if (token() && *aacct == 0)
+ *aacct = strdup(tokval);
break;
case MACDEF:
if (proxy) {
diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c
index 50574860317..5b329696a5f 100644
--- a/usr.bin/ftp/util.c
+++ b/usr.bin/ftp/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.32 2003/03/31 23:04:07 millert Exp $ */
+/* $OpenBSD: util.c,v 1.33 2003/04/05 17:19:47 deraadt Exp $ */
/* $NetBSD: util.c,v 1.12 1997/08/18 10:20:27 lukem Exp $ */
/*
@@ -35,7 +35,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: util.c,v 1.32 2003/03/31 23:04:07 millert Exp $";
+static char rcsid[] = "$OpenBSD: util.c,v 1.33 2003/04/05 17:19:47 deraadt Exp $";
#endif /* not lint */
/*
@@ -138,17 +138,22 @@ setpeer(argc, argv)
/*
* Set up defaults for FTP.
*/
- (void)strcpy(formname, "non-print"), form = FORM_N;
- (void)strcpy(modename, "stream"), mode = MODE_S;
- (void)strcpy(structname, "file"), stru = STRU_F;
- (void)strcpy(bytename, "8"), bytesize = 8;
+ (void)strlcpy(formname, "non-print", sizeof formname);
+ form = FORM_N;
+ (void)strlcpy(modename, "stream", sizeof modename);
+ mode = MODE_S;
+ (void)strlcpy(structname, "file", sizeof structname);
+ stru = STRU_F;
+ (void)strlcpy(bytename, "8", sizeof bytename);
+ bytesize = 8;
+
/*
* Set type to 0 (not specified by user),
* meaning binary by default, but don't bother
* telling server. We can use binary
* for text files unless changed by the user.
*/
- (void)strcpy(typename, "binary");
+ (void)strlcpy(typename, "binary", sizeof typename);
curtype = TYPE_A;
type = 0;
if (autologin)
@@ -308,7 +313,7 @@ tryagain:
connected = -1;
for (n = 0; n < macnum; ++n) {
if (!strcmp("init", macros[n].mac_name)) {
- (void)strcpy(line, "$init");
+ (void)strlcpy(line, "$init", sizeof line);
makeargv();
domacro(margc, margv);
break;
@@ -397,10 +402,10 @@ remglob(argv, doswitch, errbuf)
return (NULL);
}
- (void)strcpy(temp, cp);
+ (void)strlcpy(temp, cp, sizeof temp);
if (temp[len-1] != '/')
temp[len++] = '/';
- (void)strcpy(&temp[len], TMPFILE);
+ (void)strlcpy(&temp[len], TMPFILE, sizeof temp - len);
if ((fd = mkstemp(temp)) < 0) {
warn("unable to create temporary file %s", temp);
return (NULL);
diff --git a/usr.bin/patch/backupfile.c b/usr.bin/patch/backupfile.c
index c23ef037cfe..f17839de4eb 100644
--- a/usr.bin/patch/backupfile.c
+++ b/usr.bin/patch/backupfile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: backupfile.c,v 1.7 1999/12/04 21:00:03 provos Exp $ */
+/* $OpenBSD: backupfile.c,v 1.8 2003/04/05 17:17:53 deraadt Exp $ */
/* backupfile.c -- make Emacs style backup file names
Copyright (C) 1990 Free Software Foundation, Inc.
@@ -14,7 +14,7 @@
Some algorithms adapted from GNU Emacs. */
#ifndef lint
-static char rcsid[] = "$OpenBSD: backupfile.c,v 1.7 1999/12/04 21:00:03 provos Exp $";
+static char rcsid[] = "$OpenBSD: backupfile.c,v 1.8 2003/04/05 17:17:53 deraadt Exp $";
#endif /* not lint */
#include <stdio.h>
@@ -155,11 +155,13 @@ make_version_name (file, version)
int version;
{
char *backup_name;
+ size_t len;
- backup_name = malloc (strlen (file) + 16);
+ len = strlen (file) + 16;
+ backup_name = malloc (len);
if (backup_name == 0)
return 0;
- sprintf (backup_name, "%s.~%d~", file, version);
+ snprintf (backup_name, len, "%s.~%d~", file, version);
return backup_name;
}
@@ -195,13 +197,9 @@ concat (str1, str2)
char *str1, *str2;
{
char *newstr;
- int str1_length = strlen (str1);
- newstr = malloc (str1_length + strlen (str2) + 1);
- if (newstr == 0)
+ if (asprintf(&newstr, "%s%s", str1, str2) == -1)
return 0;
- strcpy (newstr, str1);
- strcpy (newstr + str1_length, str2);
return newstr;
}
diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c
index fa71846c91c..1cac5ac5c98 100644
--- a/usr.bin/patch/patch.c
+++ b/usr.bin/patch/patch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: patch.c,v 1.15 2002/07/04 04:22:48 deraadt Exp $ */
+/* $OpenBSD: patch.c,v 1.16 2003/04/05 17:17:53 deraadt Exp $ */
/* patch - a program to apply diffs to original files
*
@@ -27,7 +27,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: patch.c,v 1.15 2002/07/04 04:22:48 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: patch.c,v 1.16 2003/04/05 17:17:53 deraadt Exp $";
#endif /* not lint */
#include "INTERN.h"
@@ -96,46 +96,32 @@ char **argv;
{
/* Directory for temporary files. */
char *tmpdir;
- int tmpname_len;
tmpdir = getenv ("TMPDIR");
if (tmpdir == NULL) {
tmpdir = "/tmp";
}
- tmpname_len = strlen (tmpdir) + 20;
- TMPOUTNAME = (char *) malloc (tmpname_len);
- if (TMPOUTNAME == NULL)
+ if (asprintf(&TMPOUTNAME, "%s/patchoXXXXXX", tmpdir) == -1)
fatal1("cannot allocate memory");
- strcpy (TMPOUTNAME, tmpdir);
- strcat (TMPOUTNAME, "/patchoXXXXXX");
if ((i = mkstemp(TMPOUTNAME)) < 0)
pfatal2("can't create %s", TMPOUTNAME);
Close(i);
- TMPINNAME = (char *) malloc (tmpname_len);
- if (TMPINNAME == NULL)
+ if (asprintf(&TMPINNAME, "%s/patchiXXXXXX", tmpdir) == -1)
fatal1("cannot allocate memory");
- strcpy (TMPINNAME, tmpdir);
- strcat (TMPINNAME, "/patchiXXXXXX");
if ((i = mkstemp(TMPINNAME)) < 0)
pfatal2("can't create %s", TMPINNAME);
Close(i);
- TMPREJNAME = (char *) malloc (tmpname_len);
- if (TMPREJNAME == NULL)
+ if (asprintf(&TMPREJNAME, "%s/patchrXXXXXX", tmpdir) == -1)
fatal1("cannot allocate memory");
- strcpy (TMPREJNAME, tmpdir);
- strcat (TMPREJNAME, "/patchrXXXXXX");
if ((i = mkstemp(TMPREJNAME)) < 0)
pfatal2("can't create %s", TMPREJNAME);
Close(i);
- TMPPATNAME = (char *) malloc (tmpname_len);
- if (TMPPATNAME == NULL)
+ if (asprintf(&TMPPATNAME, "%s/patchpXXXXXX", tmpdir) == -1)
fatal1("cannot allocate memory");
- strcpy (TMPPATNAME, tmpdir);
- strcat (TMPPATNAME, "/patchpXXXXXX");
if ((i = mkstemp(TMPPATNAME)) < 0)
pfatal2("can't create %s", TMPPATNAME);
Close(i);
diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c
index 1e89649c5ce..4caf1dfc594 100644
--- a/usr.bin/patch/pch.c
+++ b/usr.bin/patch/pch.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: pch.c,v 1.11 2000/12/14 00:02:19 beck Exp $ */
+/* $OpenBSD: pch.c,v 1.12 2003/04/05 17:17:53 deraadt Exp $ */
#ifndef lint
-static char rcsid[] = "$OpenBSD: pch.c,v 1.11 2000/12/14 00:02:19 beck Exp $";
+static char rcsid[] = "$OpenBSD: pch.c,v 1.12 2003/04/05 17:17:53 deraadt Exp $";
#endif /* not lint */
#include "EXTERN.h"
@@ -454,9 +454,10 @@ another_hunk()
ret = pgets(buf, sizeof buf, pfp);
p_input_line++;
if (ret == Nullch) {
- if (p_max - p_end < 4)
- strcpy(buf, " \n"); /* assume blank lines got chopped */
- else {
+ if (p_max - p_end < 4) {
+ /* assume blank lines got chopped */
+ strlcpy(buf, " \n", sizeof buf);
+ } else {
if (repl_beginning && repl_could_be_missing) {
repl_missing = TRUE;
goto hunk_done;
@@ -595,7 +596,7 @@ another_hunk()
repl_could_be_missing = FALSE;
change_line:
if (buf[1] == '\n' && canonicalize)
- strcpy(buf+1," \n");
+ strlcpy(buf+1," \n", sizeof buf -1);
if (!isspace(buf[1]) && buf[1] != '>' && buf[1] != '<' &&
repl_beginning && repl_could_be_missing) {
repl_missing = TRUE;
@@ -807,9 +808,10 @@ another_hunk()
ret = pgets(buf, sizeof buf, pfp);
p_input_line++;
if (ret == Nullch) {
- if (p_max - filldst < 3)
- strcpy(buf, " \n"); /* assume blank lines got chopped */
- else {
+ if (p_max - filldst < 3) {
+ /* assume blank lines got chopped */
+ strlcpy(buf, " \n", sizeof buf);
+ } else {
fatal1("unexpected end of file in patch\n");
}
}
diff --git a/usr.bin/patch/util.c b/usr.bin/patch/util.c
index 4ddb1a7cb98..0a68f19deda 100644
--- a/usr.bin/patch/util.c
+++ b/usr.bin/patch/util.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: util.c,v 1.9 1999/12/04 21:00:03 provos Exp $ */
+/* $OpenBSD: util.c,v 1.10 2003/04/05 17:17:53 deraadt Exp $ */
#ifndef lint
-static char rcsid[] = "$OpenBSD: util.c,v 1.9 1999/12/04 21:00:03 provos Exp $";
+static char rcsid[] = "$OpenBSD: util.c,v 1.10 2003/04/05 17:17:53 deraadt Exp $";
#endif /* not lint */
#include "EXTERN.h"
@@ -340,7 +340,7 @@ bool striplast;
*s = '\0';
}
- strcpy(buf, "/bin/mkdir -p ");
+ strlcpy(buf, "/bin/mkdir -p ", sizeof buf);
if (strlcat(buf, tmpbuf, sizeof(buf)) >= sizeof(buf))
fatal2("buffer too small to hold %.20s...\n", tmpbuf);