aboutsummaryrefslogtreecommitdiff
path: root/findutils/xargs.c
diff options
context:
space:
mode:
authorRobert Griebl <griebl@gmx.de>2002-08-03 14:49:03 +0000
committerRobert Griebl <griebl@gmx.de>2002-08-03 14:49:03 +0000
commit0d833ca7fdf8500956191947dee4eb9bda49e86d (patch)
tree93dc58856cd7817b91bd0136867818219524d047 /findutils/xargs.c
parent49c024addd79be2b6024e33c69f5fafe9f5eff90 (diff)
downloadbusybox-w32-0d833ca7fdf8500956191947dee4eb9bda49e86d.tar.gz
busybox-w32-0d833ca7fdf8500956191947dee4eb9bda49e86d.tar.bz2
busybox-w32-0d833ca7fdf8500956191947dee4eb9bda49e86d.zip
Fixed a bug in xarg: string data was strcat'ed to a malloc'ed buffer - and
malloc does not clear memory by default (somehow this worked on x86, but not on arm)
Diffstat (limited to 'findutils/xargs.c')
-rw-r--r--findutils/xargs.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/findutils/xargs.c b/findutils/xargs.c
index c63518fe5..bb5987ec9 100644
--- a/findutils/xargs.c
+++ b/findutils/xargs.c
@@ -49,12 +49,11 @@ int xargs_main(int argc, char **argv)
49 } else { 49 } else {
50 /* concatenate all the arguments passed to xargs together */ 50 /* concatenate all the arguments passed to xargs together */
51 int i; 51 int i;
52 int len = 1; /* for the '\0' */ 52 int len = 0;
53 cmd_to_be_executed = xmalloc(80); 53 for (i = 1; i < argc; i++)
54 len += ( strlen(argv[i]) + 1 );
55 cmd_to_be_executed = xstrndup ( "", len );
54 for (i = 1; i < argc; i++) { 56 for (i = 1; i < argc; i++) {
55 len += strlen(argv[i]);
56 len += 1; /* for the space between the args */
57 cmd_to_be_executed = xrealloc(cmd_to_be_executed, len);
58 strcat(cmd_to_be_executed, argv[i]); 57 strcat(cmd_to_be_executed, argv[i]);
59 strcat(cmd_to_be_executed, " "); 58 strcat(cmd_to_be_executed, " ");
60 } 59 }
@@ -76,10 +75,9 @@ int xargs_main(int argc, char **argv)
76 continue; 75 continue;
77 76
78 /* assemble the command and execute it */ 77 /* assemble the command and execute it */
79 execstr = xcalloc(strlen(cmd_to_be_executed) + 78 execstr = xstrndup ( cmd_to_be_executed, xstrlen(cmd_to_be_executed) + xstrlen(file_to_act_on));
80 strlen(file_to_act_on) + 1, sizeof(char));
81 strcat(execstr, cmd_to_be_executed);
82 strcat(execstr, file_to_act_on); 79 strcat(execstr, file_to_act_on);
80
83 cmd_output = popen(execstr, "r"); 81 cmd_output = popen(execstr, "r");
84 if (cmd_output == NULL) 82 if (cmd_output == NULL)
85 perror_msg_and_die("popen"); 83 perror_msg_and_die("popen");