Commit 04405042 authored by Marian Durkovic's avatar Marian Durkovic

Implement shell-style escaping also for double quotes and fix bugs.

parent c1acae62
...@@ -257,27 +257,29 @@ static const char quotes[] = "\"'"; ...@@ -257,27 +257,29 @@ static const char quotes[] = "\"'";
/** /**
* FindCommandEnd: look for the end of a possibly quoted string * FindCommandEnd: look for the end of a possibly quoted string
* @return NULL on mal-formatted string, * @return NULL on mal-formatted string,
* pointer paste the last character otherwise. * pointer past the last character otherwise.
*/ */
static const char *FindCommandEnd (const char *psz_sent) static const char *FindCommandEnd (const char *psz_sent)
{ {
const char quote = strchr (quotes, psz_sent[0]) ? psz_sent[0] : 0; const char quote = strchr (quotes, psz_sent[0]) ? psz_sent[0] : 0;
char c; char c;
if (quote)
psz_sent++; // skip opening quote
while ((c = *psz_sent) != '\0') while ((c = *psz_sent) != '\0')
{ {
if ((quote == '"') && (c == '\\')) if ((quote == '"') && (c == '\\'))
{ {
psz_sent++; // move past backslash
if (*psz_sent == '\0') if (*psz_sent == '\0')
return NULL; // cannot escape "nothing" return NULL; // cannot escape "nothing"
psz_sent++; // skips escaped character
} }
else else
if (c == quote) // non-escaped matching quote if (c == quote) // non-escaped matching quote
return psz_sent + 1; return psz_sent + 1;
else else
if (isblank (c)) // non-escaped blank if ((!quote) && isspace(c)) // non-escaped blank
return psz_sent; return psz_sent;
psz_sent++; psz_sent++;
...@@ -315,23 +317,20 @@ static int Unescape (char *out, const char *in) ...@@ -315,23 +317,20 @@ static int Unescape (char *out, const char *in)
{ {
switch (c = *in++) switch (c = *in++)
{ {
case 'n': case '"':
*out++ = '\n'; *out++ = '"';
continue; continue;
case 't': case '\\':
*out++ = '\t'; *out++ = '\\';
continue; continue;
case 'r': case '\0': // should never happen
*out++ = '\r'; *out = '\0';
continue; return -1;
} }
/* None of the special cases - copy the backslash */
// Only allow printable ASCII characters *out++ = '\\';
// (in particular, no nul nor extended characters)
if (c < 32)
return -1;
} }
*out++ = c; *out++ = c;
} }
...@@ -359,7 +358,7 @@ static int ExecuteCommand( vlm_t *p_vlm, const char *psz_command, ...@@ -359,7 +358,7 @@ static int ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
{ {
const char *psz_temp; const char *psz_temp;
if(isblank (*psz_command)) if(isspace (*psz_command))
{ {
psz_command++; psz_command++;
continue; continue;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment