Skip to content

Commit f336af1

Browse files
H. Peter AnvinJunio C Hamano
authored andcommitted
Make rsh.c use sq_quote_buf()
Make rsh.c use sq_quote_buf() Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 977ed47 commit f336af1

File tree

1 file changed

+5
-41
lines changed

1 file changed

+5
-41
lines changed

rsh.c

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,16 @@
1-
#include "rsh.h"
2-
31
#include <string.h>
42
#include <sys/types.h>
53
#include <sys/socket.h>
64

5+
#include "rsh.h"
6+
#include "quote.h"
77
#include "cache.h"
88

99
#define COMMAND_SIZE 4096
1010

1111
/*
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.
5014
*/
5115
static int add_to_string(char **ptrp, int *sizep, const char *str, int quote)
5216
{
@@ -56,7 +20,7 @@ static int add_to_string(char **ptrp, int *sizep, const char *str, int quote)
5620
int err = 0;
5721

5822
if ( quote ) {
59-
oc = shell_quote(p, size, str);
23+
oc = sq_quote_buf(p, size, str);
6024
} else {
6125
oc = strlen(str);
6226
memcpy(p, str, (oc >= size) ? size-1 : oc);

0 commit comments

Comments
 (0)