summaryrefslogtreecommitdiff
path: root/usr.bin/patch
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1996-09-24 04:19:31 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1996-09-24 04:19:31 +0000
commitaf0ffdb2def8ccf3dfa0304b9bc45ad743f4cb46 (patch)
treeb5801c95be69301bd73eea07400899e5383dff80 /usr.bin/patch
parent3a17bdd392064c10ca3236e7c83d374d3344f842 (diff)
sprintf -> snprintf except where guaranteed safe.
Diffstat (limited to 'usr.bin/patch')
-rw-r--r--usr.bin/patch/common.h10
-rw-r--r--usr.bin/patch/inp.c14
-rw-r--r--usr.bin/patch/patch.c18
-rw-r--r--usr.bin/patch/pch.c19
-rw-r--r--usr.bin/patch/util.c8
5 files changed, 35 insertions, 34 deletions
diff --git a/usr.bin/patch/common.h b/usr.bin/patch/common.h
index 96421b22d50..adfe4ac4e42 100644
--- a/usr.bin/patch/common.h
+++ b/usr.bin/patch/common.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: common.h,v 1.4 1996/09/24 02:58:53 millert Exp $ */
+/* $OpenBSD: common.h,v 1.5 1996/09/24 04:19:25 millert Exp $ */
#define DEBUGGING
@@ -16,7 +16,7 @@
#define Close (void)close
#define Fclose (void)fclose
#define Fflush (void)fflush
-#define Sprintf (void)sprintf
+#define Snprintf (void)snprintf
#define Strcpy (void)strcpy
#define Strcat (void)strcat
@@ -82,8 +82,6 @@
#define strnNE(s1,s2,l) (strncmp(s1, s2, l))
#define strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
-#define Mkstemp mkstemp
-
/* typedefs */
typedef char bool;
@@ -172,9 +170,9 @@ char *rindex();
int mkstemp();
#if 0 /* This can cause a prototype conflict. */
#ifdef CHARSPRINTF
-char *sprintf();
+char *snprintf();
#else
-int sprintf();
+int snprintf();
#endif
#endif
diff --git a/usr.bin/patch/inp.c b/usr.bin/patch/inp.c
index 86c3b3759a6..d3917a88de0 100644
--- a/usr.bin/patch/inp.c
+++ b/usr.bin/patch/inp.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: inp.c,v 1.4 1996/07/01 20:40:07 deraadt Exp $ */
+/* $OpenBSD: inp.c,v 1.5 1996/09/24 04:19:26 millert Exp $ */
#ifndef lint
-static char rcsid[] = "$OpenBSD: inp.c,v 1.4 1996/07/01 20:40:07 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: inp.c,v 1.5 1996/09/24 04:19:26 millert Exp $";
#endif /* not lint */
#include "EXTERN.h"
@@ -103,17 +103,17 @@ char *filename;
s = lbuf + 20;
strncpy(s, filename, pathlen);
-#define try(f, a1, a2) (Sprintf(s + pathlen, f, a1, a2), stat(s, &cstat) == 0)
+#define try(f, a1, a2) (Snprintf(s + pathlen, sizeof lbuf - (s + pathlen - lbuf), f, a1, a2), stat(s, &cstat) == 0)
if ( try("RCS/%s%s", filebase, RCSSUFFIX)
|| try("RCS/%s" , filebase, 0)
|| try( "%s%s", filebase, RCSSUFFIX)) {
- Sprintf(buf, CHECKOUT, filename);
- Sprintf(lbuf, RCSDIFF, filename);
+ Snprintf(buf, sizeof buf, CHECKOUT, filename);
+ Snprintf(lbuf, sizeof lbuf, RCSDIFF, filename);
cs = "RCS";
} else if ( try("SCCS/%s%s", SCCSPREFIX, filebase)
|| try( "%s%s", SCCSPREFIX, filebase)) {
- Sprintf(buf, GET, s);
- Sprintf(lbuf, SCCSDIFF, s, filename);
+ Snprintf(buf, sizeof buf, GET, s);
+ Snprintf(lbuf, sizeof lbuf, SCCSDIFF, s, filename);
cs = "SCCS";
} else if (statfailed)
fatal2("can't find %s\n", filename);
diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c
index 41884781e03..be4b7f4ac61 100644
--- a/usr.bin/patch/patch.c
+++ b/usr.bin/patch/patch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: patch.c,v 1.7 1996/09/24 02:58:52 millert Exp $ */
+/* $OpenBSD: patch.c,v 1.8 1996/09/24 04:19:28 millert Exp $ */
/* patch - a program to apply diffs to original files
*
@@ -9,7 +9,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: patch.c,v 1.7 1996/09/24 02:58:52 millert Exp $";
+static char rcsid[] = "$OpenBSD: patch.c,v 1.8 1996/09/24 04:19:28 millert Exp $";
#endif /* not lint */
#include "INTERN.h"
@@ -81,28 +81,28 @@ char **argv;
TMPOUTNAME = (char *) malloc (tmpname_len);
strcpy (TMPOUTNAME, tmpdir);
strcat (TMPOUTNAME, "/patchoXXXXXX");
- if ((i = Mkstemp(TMPOUTNAME)) < 0)
+ if ((i = mkstemp(TMPOUTNAME)) < 0)
pfatal2("can't create %s", TMPOUTNAME);
Close(i);
TMPINNAME = (char *) malloc (tmpname_len);
strcpy (TMPINNAME, tmpdir);
strcat (TMPINNAME, "/patchiXXXXXX");
- if ((i = Mkstemp(TMPINNAME)) < 0)
+ if ((i = mkstemp(TMPINNAME)) < 0)
pfatal2("can't create %s", TMPINNAME);
Close(i);
TMPREJNAME = (char *) malloc (tmpname_len);
strcpy (TMPREJNAME, tmpdir);
strcat (TMPREJNAME, "/patchrXXXXXX");
- if ((i = Mkstemp(TMPREJNAME)) < 0)
+ if ((i = mkstemp(TMPREJNAME)) < 0)
pfatal2("can't create %s", TMPREJNAME);
Close(i);
TMPPATNAME = (char *) malloc (tmpname_len);
strcpy (TMPPATNAME, tmpdir);
strcat (TMPPATNAME, "/patchpXXXXXX");
- if ((i = Mkstemp(TMPPATNAME)) < 0)
+ if ((i = mkstemp(TMPPATNAME)) < 0)
pfatal2("can't create %s", TMPPATNAME);
Close(i);
}
@@ -488,9 +488,9 @@ get_some_switches()
s = nextarg();
if (!isalpha(*s) && '_' != *s)
fatal1("argument to -D is not an identifier\n");
- Sprintf(if_defined, "#ifdef %s\n", s);
- Sprintf(not_defined, "#ifndef %s\n", s);
- Sprintf(end_defined, "#endif /* %s */\n", s);
+ Snprintf(if_defined, sizeof if_defined, "#ifdef %s\n", s);
+ Snprintf(not_defined, sizeof not_defined, "#ifndef %s\n", s);
+ Snprintf(end_defined, sizeof end_defined, "#endif /* %s */\n", s);
break;
case 'e':
diff_type = ED_DIFF;
diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c
index ece445ed578..abed3936332 100644
--- a/usr.bin/patch/pch.c
+++ b/usr.bin/patch/pch.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: pch.c,v 1.6 1996/09/23 10:54:22 deraadt Exp $ */
+/* $OpenBSD: pch.c,v 1.7 1996/09/24 04:19:29 millert Exp $ */
#ifndef lint
-static char rcsid[] = "$OpenBSD: pch.c,v 1.6 1996/09/23 10:54:22 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: pch.c,v 1.7 1996/09/24 04:19:29 millert Exp $";
#endif /* not lint */
#include "EXTERN.h"
@@ -781,14 +781,16 @@ another_hunk()
fillsrc = 1;
filldst = fillsrc + p_ptrn_lines;
p_end = filldst + p_repl_lines;
- Sprintf(buf,"*** %ld,%ld ****\n",p_first,p_first + p_ptrn_lines - 1);
+ Snprintf(buf, sizeof buf, "*** %ld,%ld ****\n", p_first,
+ p_first + p_ptrn_lines - 1);
p_line[0] = savestr(buf);
if (out_of_mem) {
p_end = -1;
return FALSE;
}
p_char[0] = '*';
- Sprintf(buf,"--- %ld,%ld ----\n",p_newfirst,p_newfirst+p_repl_lines-1);
+ Snprintf(buf, sizeof buf, "--- %ld,%ld ----\n", p_newfirst,
+ p_newfirst + p_repl_lines - 1);
p_line[filldst] = savestr(buf);
if (out_of_mem) {
p_end = 0;
@@ -920,7 +922,8 @@ another_hunk()
grow_hunkmax();
p_newfirst = min;
p_repl_lines = max - min + 1;
- Sprintf(buf, "*** %ld,%ld\n", p_first, p_first + p_ptrn_lines - 1);
+ Snprintf(buf, sizeof buf, "*** %ld,%ld\n", p_first,
+ p_first + p_ptrn_lines - 1);
p_line[0] = savestr(buf);
if (out_of_mem) {
p_end = -1;
@@ -952,7 +955,7 @@ another_hunk()
if (*buf != '-')
fatal2("--- expected at line %ld of patch\n", p_input_line);
}
- Sprintf(buf, "--- %ld,%ld\n", min, max);
+ Snprintf(buf, sizeof(buf), "--- %ld,%ld\n", min, max);
p_line[i] = savestr(buf);
if (out_of_mem) {
p_end = i-1;
@@ -1227,9 +1230,9 @@ do_ed_script()
Unlink(TMPOUTNAME);
copy_file(filearg[0], TMPOUTNAME);
if (verbose)
- Sprintf(buf, "/bin/ed %s", TMPOUTNAME);
+ Snprintf(buf, sizeof buf, "/bin/ed %s", TMPOUTNAME);
else
- Sprintf(buf, "/bin/ed - %s", TMPOUTNAME);
+ Snprintf(buf, sizeof buf, "/bin/ed - %s", TMPOUTNAME);
pipefp = popen(buf, "w");
}
for (;;) {
diff --git a/usr.bin/patch/util.c b/usr.bin/patch/util.c
index b67a0b8a5bd..1029caca973 100644
--- a/usr.bin/patch/util.c
+++ b/usr.bin/patch/util.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: util.c,v 1.2 1996/06/10 11:21:34 niklas Exp $ */
+/* $OpenBSD: util.c,v 1.3 1996/09/24 04:19:30 millert Exp $ */
#ifndef lint
-static char rcsid[] = "$OpenBSD: util.c,v 1.2 1996/06/10 11:21:34 niklas Exp $";
+static char rcsid[] = "$OpenBSD: util.c,v 1.3 1996/09/24 04:19:30 millert Exp $";
#endif /* not lint */
#include "EXTERN.h"
@@ -244,7 +244,7 @@ long arg1,arg2,arg3;
int r;
bool tty2 = isatty(2);
- Sprintf(buf, pat, arg1, arg2, arg3);
+ Snprintf(buf, sizeof buf, pat, arg1, arg2, arg3);
Fflush(stderr);
write(2, buf, strlen(buf));
if (tty2) { /* might be redirected to a file */
@@ -428,7 +428,7 @@ int assume_exists;
/* Put any leading path into `tmpbuf'. */
strncpy(tmpbuf, name, pathlen);
-#define try(f, a1, a2) (Sprintf(tmpbuf + pathlen, f, a1, a2), stat(tmpbuf, &filestat) == 0)
+#define try(f, a1, a2) (Snprintf(tmpbuf + pathlen, sizeof tmpbuf - pathlen, f, a1, a2), stat(tmpbuf, &filestat) == 0)
if ( try("RCS/%s%s", filebase, RCSSUFFIX)
|| try("RCS/%s" , filebase, 0)
|| try( "%s%s", filebase, RCSSUFFIX)