{"thread":{"id":"1930","subject":"[PATCH] rsh.c unterminated string","startedAt":"2005-09-23T23:30:50Z","lastAt":"2005-09-23T23:30:50Z","messageCount":1,"participants":["H. Peter Anvin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"9205","messageId":"4334902A.3010905@zytor.com","threadId":"1930","inReplyTo":null,"subject":"[PATCH] rsh.c unterminated string","fromName":"H. Peter Anvin","fromEmail":"hpa@zytor.com","sentAt":"2005-09-23T23:30:50Z","receivedAt":"2005-09-23T23:30:50Z","isPatch":true,"sender":{"key":"hpa@zytor.com","avatar":null},"body":"The change I made to rsh.c would leave the string unterminated under \ncertain conditions, which unfortunately always applied!  This patch \nfixes this.  For some reason this never bit on i386 or ppc, but bit me \non x86-64.\n\nSigned-off-by: H. Peter Anvin <hpa@zytor.com>\n\n\nFix situation where the buffer was not properly null-terminated.\n\n---\ncommit 62f7819792e7152ae0dc241ed2f7e05e10c0d345\ntree 865683d54a0c4d7604711d6b74233f79291eb8ac\nparent acfadcfb48e34fdc441e9cffbb385fce9693b363\nauthor Peter Anvin <hpa@tazenda.sc.orionmulti.com> Fri, 23 Sep 2005 16:22:33 -0700\ncommitter Peter Anvin <hpa@tazenda.sc.orionmulti.com> Fri, 23 Sep 2005 16:22:33 -0700\n\n rsh.c |   10 +++++-----\n 1 files changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/rsh.c b/rsh.c\n--- a/rsh.c\n+++ b/rsh.c\n@@ -53,6 +53,7 @@ static int add_to_string(char **ptrp, in\n \tchar *p = *ptrp;\n \tint size = *sizep;\n \tint oc;\n+\tint err = 0;\n \n \tif ( quote ) {\n \t\toc = shell_quote(p, size, str);\n@@ -62,15 +63,14 @@ static int add_to_string(char **ptrp, in\n \t}\n \n \tif ( oc >= size ) {\n-\t\tp[size-1] = '\\0';\n-\t\t*ptrp += size-1;\n-\t\t*sizep = 1;\n-\t\treturn 1;\t/* Overflow, string unusable */\n+\t\terr = 1;\n+\t\toc = size-1;\n \t}\n \n \t*ptrp  += oc;\n+\t**ptrp  = '\\0';\n \t*sizep -= oc;\n-\treturn 0;\n+\treturn err;\n }\n \n int setup_connection(int *fd_in, int *fd_out, const char *remote_prog, \n"}]}