From 35b8a29eb2be26dda8dd2fec32cb1ae73bafeb1e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 29 Dec 2015 01:06:41 +0100 Subject: more character that are not sh safe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/satd-list.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/satd-list.c b/src/satd-list.c index e6bcfd7..a9fce0f 100644 --- a/src/satd-list.c +++ b/src/satd-list.c @@ -20,7 +20,6 @@ * DEALINGS IN THE SOFTWARE. */ #include "daemon.h" -#include @@ -39,18 +38,20 @@ static char * quote(const char *str) { - size_t in = 0; /* < ' ' */ - size_t sn = 0; /* = ' ', '"' or '$' */ - size_t bn = 0; /* = '\\' */ - size_t qn = 0; /* = '\'' */ - size_t rn = 0; /* other */ +#define UNSAFE(c) strchr(" \"$()[]{};|&^#!?*~`<>", c) + + size_t in = 0; /* < ' ' */ + size_t sn = 0; /* in UNSAFE */ + size_t bn = 0; /* = '\\' */ + size_t qn = 0; /* = '\'' */ + size_t rn = 0; /* other */ size_t n, i = 0; const unsigned char *s; char *rc; for (s = (const unsigned char *)str; *s; s++) { if (*s < ' ') in++; - else if (*s == ' ') sn++; + else if (UNSAFE(*s)) sn++; else if (*s == '"') sn++; else if (*s == '$') sn++; else if (*s == '\\') bn++; @@ -86,9 +87,6 @@ quote(const char *str) rc[i++] = "0123456789ABCDEF"[(*s >> 4) & 15]; rc[i++] = "0123456789ABCDEF"[(*s >> 0) & 15]; } - else if (*s == ' ') rc[i++] = (char)*s; - else if (*s == '"') rc[i++] = (char)*s; - else if (*s == '$') rc[i++] = (char)*s; else if (*s == '\\') rc[i++] = '\\', rc[i++] = (char)*s; else if (*s == '\'') rc[i++] = '\\', rc[i++] = (char)*s; else rc[i++] = (char)*s; -- cgit v1.2.3-70-g09d2