[PATCH] rsh.c unterminated string
The change I made to rsh.c would leave the string unterminated under certain conditions, which unfortunately always applied! This patch fixes this. For some reason this never bit on i386 or ppc, but bit me on x86-64. Fix situation where the buffer was not properly null-terminated. Signed-off-by: H. Peter Anvin <hpa@zytor.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
H. Peter Anvin committed
Sep 23, 2005 at 16:30 UTC
e433b071fed7dbdf91437b489e261b86288542d8
1 file changed
+5
-5
rsh.c
+5
-5
@@ -53,6 +53,7 @@ static int add_to_string(char **ptrp, int *sizep, const char *str, int quote)
53
char *p = *ptrp;
54
int size = *sizep;
55
int oc;
56
+ int err = 0;
57
58
if ( quote ) {
59
oc = shell_quote(p, size, str);
@@ -62,15 +63,14 @@ static int add_to_string(char **ptrp, int *sizep, const char *str, int quote)
63
}
64
65
if ( oc >= size ) {
65
- p[size-1] = '\0';
66
- *ptrp += size-1;
67
- *sizep = 1;
68
- return 1; /* Overflow, string unusable */
66
+ err = 1;
67
+ oc = size-1;
68
}
69
70
*ptrp += oc;
71
+ **ptrp = '\0';
72
*sizep -= oc;
73
- return 0;
73
+ return err;
74
}
75
76
int setup_connection(int *fd_in, int *fd_out, const char *remote_prog,