@matheusbsbs / matheus-bagliano / commits / f336af1711
Fork 0

Make rsh.c use sq_quote_buf()

Make rsh.c use sq_quote_buf() Signed-off-by: Junio C Hamano <junkio@cox.net>

H. Peter Anvin committed Oct 10, 2005 at 14:46 UTC f336af1711f86e8b00e85eec3b3f73f7a8e4bed0
1 file changed +5 -41
rsh.c
+5 -41
@@ -1,52 +1,16 @@
1 -#include "rsh.h"
2 -
1 #include <string.h>
2 #include <sys/types.h>
3 #include <sys/socket.h>
4
5 +#include "rsh.h"
6 +#include "quote.h"
7 #include "cache.h"
8
9 #define COMMAND_SIZE 4096
10
11 /*
12 - * Write a shell-quoted version of a string into a buffer, and
13 - * return bytes that ought to be output excluding final null.
14 - */
15 -static int shell_quote(char *buf, int nmax, const char *str)
16 -{
17 - char ch;
18 - int nq;
19 - int oc = 0;
20 -
21 - while ( (ch = *str++) ) {
22 - nq = 0;
23 - if ( strchr(" !\"#$%&\'()*;<=>?[\\]^`{|}", ch) )
24 - nq = 1;
25 -
26 - if ( nq ) {
27 - if ( nmax > 1 ) {
28 - *buf++ = '\\';
29 - nmax--;
30 - }
31 - oc++;
32 - }
33 -
34 - if ( nmax > 1 ) {
35 - *buf++ = ch;
36 - nmax--;
37 - }
38 - oc++;
39 - }
40 -
41 - if ( nmax )
42 - *buf = '\0';
43 -
44 - return oc;
45 -}
46 -
47 -/*
48 - * Append a string to a string buffer, with or without quoting. Return true
49 - * if the buffer overflowed.
12 + * Append a string to a string buffer, with or without shell quoting.
13 + * Return true if the buffer overflowed.
14 */
15 static int add_to_string(char **ptrp, int *sizep, const char *str, int quote)
16 {
@@ -56,7 +20,7 @@ static int add_to_string(char **ptrp, int *sizep, const char *str, int quote)
20 int err = 0;
21
22 if ( quote ) {
59 - oc = shell_quote(p, size, str);
23 + oc = sq_quote_buf(p, size, str);
24 } else {
25 oc = strlen(str);
26 memcpy(p, str, (oc >= size) ? size-1 : oc);