{"thread":{"id":"2062","subject":"[PATCH 2/3] Make rsh.c use sq_quote_buf()","startedAt":"2005-10-10T20:50:06Z","lastAt":"2005-10-10T20:50:06Z","messageCount":1,"participants":["H. Peter Anvin"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"9924","messageId":"434AD3FE.204@zytor.com","threadId":"2062","inReplyTo":null,"subject":"[PATCH 2/3] Make rsh.c use sq_quote_buf()","fromName":"H. Peter Anvin","fromEmail":"hpa@zytor.com","sentAt":"2005-10-10T20:50:06Z","receivedAt":"2005-10-10T20:50:06Z","isPatch":true,"sender":{"key":"hpa@zytor.com","avatar":null},"body":"\n\nMake rsh.c use sq_quote_buf()\n\n---\ncommit 16e46159b554116a7d95a206913fcdf7e79e07d0\ntree c075951382add702148d7a2c2b4e0298efab8082\nparent cc114823f72bd8d912abf7f7a7515853c554a9f3\nauthor Peter Anvin <hpa@tazenda.sc.orionmulti.com> Mon, 10 Oct 2005 12:23:44 -0700\ncommitter Peter Anvin <hpa@tazenda.sc.orionmulti.com> Mon, 10 Oct 2005 12:23:44 -0700\n\n rsh.c |   46 +++++-----------------------------------------\n 1 files changed, 5 insertions(+), 41 deletions(-)\n\ndiff --git a/rsh.c b/rsh.c\nindex bad5cff..8278eab 100644\n--- a/rsh.c\n+++ b/rsh.c\n@@ -1,52 +1,16 @@\n-#include \"rsh.h\"\n-\n #include <string.h>\n #include <sys/types.h>\n #include <sys/socket.h>\n \n+#include \"rsh.h\"\n+#include \"quote.h\"\n #include \"cache.h\"\n \n #define COMMAND_SIZE 4096\n \n /*\n- * Write a shell-quoted version of a string into a buffer, and\n- * return bytes that ought to be output excluding final null.\n- */\n-static int shell_quote(char *buf, int nmax, const char *str)\n-{\n-\tchar ch;\n-\tint nq;\n-\tint oc = 0;\n-\n-\twhile ( (ch = *str++) ) {\n-\t\tnq = 0;\n-\t\tif ( strchr(\" !\\\"#$%&\\'()*;<=>?[\\\\]^`{|}\", ch) )\n-\t\t\tnq = 1;\n-\n-\t\tif ( nq ) {\n-\t\t\tif ( nmax > 1 ) {\n-\t\t\t\t*buf++ = '\\\\';\n-\t\t\t\tnmax--;\n-\t\t\t}\n-\t\t\toc++;\n-\t\t}\n-\n-\t\tif ( nmax > 1 ) {\n-\t\t\t*buf++ = ch;\n-\t\t\tnmax--;\n-\t\t}\n-\t\toc++;\n-\t}\n-\n-\tif ( nmax )\n-\t\t*buf = '\\0';\n-\n-\treturn oc;\n-}\n-\t\t\t\n-/*\n- * Append a string to a string buffer, with or without quoting.  Return true\n- * if the buffer overflowed.\n+ * Append a string to a string buffer, with or without shell quoting.\n+ * Return true if the buffer overflowed.\n  */\n static int add_to_string(char **ptrp, int *sizep, const char *str, int quote)\n {\n@@ -56,7 +20,7 @@ static int add_to_string(char **ptrp, in\n \tint err = 0;\n \n \tif ( quote ) {\n-\t\toc = shell_quote(p, size, str);\n+\t\toc = sq_quote_buf(p, size, str);\n \t} else {\n \t\toc = strlen(str);\n \t\tmemcpy(p, str, (oc >= size) ? size-1 : oc);\n"}]}