diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-04-28 23:15:29 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-04-28 23:15:29 +0000 |
commit | 8ae349c5ed589e74d1df898832c03ccecac032be (patch) | |
tree | 2eb84728cf59be274bd4c539dfbe9fa2570ede59 /gnu/usr.bin | |
parent | e7a975b5938207593369f6bd83f5cee9ced709b0 (diff) |
string cleaning
Diffstat (limited to 'gnu/usr.bin')
-rw-r--r-- | gnu/usr.bin/diff/diff.c | 11 | ||||
-rw-r--r-- | gnu/usr.bin/diff/diff3.c | 10 | ||||
-rw-r--r-- | gnu/usr.bin/diff/regex.c | 10 | ||||
-rw-r--r-- | gnu/usr.bin/diff/sdiff.c | 14 | ||||
-rw-r--r-- | gnu/usr.bin/diff/util.c | 20 |
5 files changed, 33 insertions, 32 deletions
diff --git a/gnu/usr.bin/diff/diff.c b/gnu/usr.bin/diff/diff.c index ab1549be864..ac84d62bcaf 100644 --- a/gnu/usr.bin/diff/diff.c +++ b/gnu/usr.bin/diff/diff.c @@ -86,8 +86,8 @@ option_list (optionvec, count) for (i = 0; i < count; i++) { - strcat (result, " "); - strcat (result, optionvec[i]); + strlcat (result, " ", length + 1); + strlcat (result, optionvec[i], length + 1); } return result; @@ -319,10 +319,11 @@ main (argc, argv) int i, err = 0; static char const C_ifdef_group_formats[] = "#ifndef %s\n%%<#endif /* not %s */\n%c#ifdef %s\n%%>#endif /* %s */\n%c%%=%c#ifndef %s\n%%<#else /* %s */\n%%>#endif /* %s */\n"; - char *b = xmalloc (sizeof (C_ifdef_group_formats) + size_t len = sizeof (C_ifdef_group_formats) + 7 * strlen(optarg) - 14 /* 7*"%s" */ - - 8 /* 5*"%%" + 3*"%c" */); - sprintf (b, C_ifdef_group_formats, + - 8 /* 5*"%%" + 3*"%c" */; + char *b = xmalloc (len); + snprintf (b, len, C_ifdef_group_formats, optarg, optarg, 0, optarg, optarg, 0, 0, optarg, optarg, optarg); diff --git a/gnu/usr.bin/diff/diff3.c b/gnu/usr.bin/diff/diff3.c index 5d94ab866db..18e09e86992 100644 --- a/gnu/usr.bin/diff/diff3.c +++ b/gnu/usr.bin/diff/diff3.c @@ -1152,7 +1152,8 @@ read_diff (filea, fileb, output_placement) *ap++ = diff_program; if (always_text) *ap++ = "-a"; - sprintf (horizon_arg, "--horizon-lines=%d", horizon_lines); + snprintf (horizon_arg, sizeof horizon_arg, "--horizon-lines=%d", + horizon_lines); *ap++ = horizon_arg; *ap++ = "--"; *ap++ = filea; @@ -1188,10 +1189,11 @@ read_diff (filea, fileb, output_placement) #else /* ! HAVE_FORK */ FILE *fpipe; - char *command = xmalloc (sizeof (diff_program) + 30 + INT_STRLEN_BOUND (int) - + 4 * (strlen (filea) + strlen (fileb))); + size_t len = sizeof (diff_program) + 30 + INT_STRLEN_BOUND (int) + + 4 * (strlen (filea) + strlen (fileb)); + char *command = xmalloc (len); char *p; - sprintf (command, "%s -a --horizon-lines=%d -- ", + snprintf (command, len, "%s -a --horizon-lines=%d -- ", diff_program, horizon_lines); p = command + strlen (command); SYSTEM_QUOTE_ARG (p, filea); diff --git a/gnu/usr.bin/diff/regex.c b/gnu/usr.bin/diff/regex.c index 5d8c4566f5f..5ae7b524cc5 100644 --- a/gnu/usr.bin/diff/regex.c +++ b/gnu/usr.bin/diff/regex.c @@ -5200,15 +5200,7 @@ regerror (errcode, preg, errbuf, errbuf_size) msg_size = strlen (msg) + 1; /* Includes the null. */ if (errbuf_size != 0) - { - if (msg_size > errbuf_size) - { - strncpy (errbuf, msg, errbuf_size - 1); - errbuf[errbuf_size - 1] = 0; - } - else - strcpy (errbuf, msg); - } + strlcpy (errbuf, msg, errbuf_size); return msg_size; } diff --git a/gnu/usr.bin/diff/sdiff.c b/gnu/usr.bin/diff/sdiff.c index b4f3ab77e53..b87992798ba 100644 --- a/gnu/usr.bin/diff/sdiff.c +++ b/gnu/usr.bin/diff/sdiff.c @@ -973,8 +973,9 @@ edit (left, lenl, right, lenr, outfile) { int wstatus; #if ! HAVE_FORK - char *command = xmalloc (strlen (edbin) + strlen (tmpname) + 2); - sprintf (command, "%s %s", edbin, tmpname); + size_t len = strlen (edbin) + strlen (tmpname) + 2; + char *command = xmalloc (len); + snprintf (command, len, "%s %s", edbin, tmpname); wstatus = system (command); free (command); #else /* HAVE_FORK */ @@ -1145,7 +1146,7 @@ private_tempnam () { char const *dir = getenv (TMPDIR_ENV); static char const tmpdir[] = PVT_tmpdir; - size_t index; + size_t index, len; char *buf; pid_t pid = getpid (); size_t dlen; @@ -1159,9 +1160,10 @@ private_tempnam () while (dlen && dir[dlen - 1] == '/') --dlen; - buf = xmalloc (dlen + 1 + 3 + 5 + 1 + 3 + 1); + len = dlen + 1 + 3 + 5 + 1 + 3 + 1; + buf = xmalloc (len); - sprintf (buf, "%.*s/.", (int) dlen, dir); + snprintf (buf, len, "%.*s/.", (int) dlen, dir); if (diraccess (buf)) { for (index = 0; @@ -1174,7 +1176,7 @@ private_tempnam () We use a single counter in INDEX to cycle each of three character positions through each of 62 possible letters. */ - sprintf (buf, "%.*s/dif%.5lu.%c%c%c", (int) dlen, dir, + snprintf (buf, len, "%.*s/dif%.5lu.%c%c%c", (int) dlen, dir, (unsigned long) pid % 100000, letters[index % (sizeof (letters) - 1)], letters[(index / (sizeof (letters) - 1)) diff --git a/gnu/usr.bin/diff/util.c b/gnu/usr.bin/diff/util.c index 98de0d7d6b6..3a852cca757 100644 --- a/gnu/usr.bin/diff/util.c +++ b/gnu/usr.bin/diff/util.c @@ -169,18 +169,21 @@ void begin_output () { char *name; + size_t len; if (outfile != 0) return; /* Construct the header of this piece of diff. */ - name = xmalloc (strlen (current_name0) + strlen (current_name1) - + strlen (switch_string) + 7); + len = strlen (current_name0) + strlen (current_name1) + + strlen (switch_string) + 7; + name = xmalloc (len); /* Posix.2 section 4.17.6.1.1 specifies this format. But there is a bug in the first printing (IEEE Std 1003.2-1992 p 251 l 3304): it says that we must print only the last component of the pathnames. This requirement is silly and does not match historical practice. */ - sprintf (name, "diff%s %s %s", switch_string, current_name0, current_name1); + snprintf (name, len, "diff%s %s %s", switch_string, current_name0, + current_name1); if (paginate_flag) { @@ -219,10 +222,11 @@ begin_output () pfatal_with_name ("fdopen"); } #else /* ! HAVE_FORK */ - char *command = xmalloc (4 * strlen (name) + strlen (PR_PROGRAM) + 10); + size_t len = 4 * strlen (name) + strlen (PR_PROGRAM) + 10; + char *command = xmalloc (len); char *p; char const *a = name; - sprintf (command, "%s -F -h ", PR_PROGRAM); + snprintf (command, len, "%s -F -h ", PR_PROGRAM); p = command + strlen (command); SYSTEM_QUOTE_ARG (p, a); *p = 0; @@ -725,9 +729,9 @@ char * concat (s1, s2, s3) char const *s1, *s2, *s3; { - size_t len = strlen (s1) + strlen (s2) + strlen (s3); - char *new = xmalloc (len + 1); - sprintf (new, "%s%s%s", s1, s2, s3); + size_t len = strlen (s1) + strlen (s2) + strlen (s3) + 1; + char *new = xmalloc (len); + snprintf (new, len, "%s%s%s", s1, s2, s3); return new; } |