Skip to content

Commit e433b07

Browse files
H. Peter AnvinJunio C Hamano
authored andcommitted
[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>
1 parent 628cd54 commit e433b07

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

rsh.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static int add_to_string(char **ptrp, int *sizep, const char *str, int quote)
5353
char *p = *ptrp;
5454
int size = *sizep;
5555
int oc;
56+
int err = 0;
5657

5758
if ( quote ) {
5859
oc = shell_quote(p, size, str);
@@ -62,15 +63,14 @@ static int add_to_string(char **ptrp, int *sizep, const char *str, int quote)
6263
}
6364

6465
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;
6968
}
7069

7170
*ptrp += oc;
71+
**ptrp = '\0';
7272
*sizep -= oc;
73-
return 0;
73+
return err;
7474
}
7575

7676
int setup_connection(int *fd_in, int *fd_out, const char *remote_prog,

0 commit comments

Comments
 (0)