Skip to content

Commit

Permalink
[PATCH] rsh.c unterminated string
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
H. Peter Anvin authored and Junio C Hamano committed Sep 24, 2005
1 parent 628cd54 commit e433b07
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions rsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static int add_to_string(char **ptrp, int *sizep, const char *str, int quote)
char *p = *ptrp;
int size = *sizep;
int oc;
int err = 0;

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

if ( oc >= size ) {
p[size-1] = '\0';
*ptrp += size-1;
*sizep = 1;
return 1; /* Overflow, string unusable */
err = 1;
oc = size-1;
}

*ptrp += oc;
**ptrp = '\0';
*sizep -= oc;
return 0;
return err;
}

int setup_connection(int *fd_in, int *fd_out, const char *remote_prog,
Expand Down

0 comments on commit e433b07

Please sign in to comment.