summaryrefslogtreecommitdiffstats
path: root/usr.bin/patch
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 /usr.bin/patch
parentsnprintf; ok miod ho henning (diff)
downloadwireguard-openbsd-1f7e104bfc8b45091d63639f00b06131ee5e7ef1.tar.xz
wireguard-openbsd-1f7e104bfc8b45091d63639f00b06131ee5e7ef1.zip
string fixes; ok miod henning
Diffstat (limited to 'usr.bin/patch')
-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
4 files changed, 27 insertions, 41 deletions
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);