Sanitize error text to reduce TCL errors

This commit is contained in:
Douglas Clowes
2014-04-04 11:54:21 +11:00
parent f9bff7f4f2
commit 1692e0d4d4

View File

@ -402,6 +402,7 @@ static char *SctActionHandler(void *actionData, char *lastReply,
char *errorScript = NULL; char *errorScript = NULL;
char *send = NULL; char *send = NULL;
int i; int i;
int j;
SConnection *con; SConnection *con;
char eprop[80]; char eprop[80];
char msg[1024]; char msg[1024];
@ -516,6 +517,21 @@ static char *SctActionHandler(void *actionData, char *lastReply,
if (strcasecmp(data->name, "read") == 0) { if (strcasecmp(data->name, "read") == 0) {
SetHdbProperty(node, "geterror", result); SetHdbProperty(node, "geterror", result);
} }
/* Sanitize the text to reduce TCL problems with unbalanced and substituted items */
for (j = 0; msg[j]; ++j) {
switch (msg[j]) {
case '{':
case '}':
case '[':
case ']':
case '<':
case '>':
case '\'':
case '"':
case '$':
msg[j] = '_';
}
}
SetHdbProperty(node, eprop, msg); SetHdbProperty(node, eprop, msg);
blank = strchr(origScript, ' '); blank = strchr(origScript, ' ');
if (blank != NULL) { if (blank != NULL) {
@ -531,6 +547,21 @@ static char *SctActionHandler(void *actionData, char *lastReply,
} }
cnt++; cnt++;
snprintf(msg, sizeof msg, "%dx {%s}: %s", cnt, origScript, result); snprintf(msg, sizeof msg, "%dx {%s}: %s", cnt, origScript, result);
/* Sanitize the text to reduce TCL problems with unbalanced and substituted items */
for (j = 0; msg[j]; ++j) {
switch (msg[j]) {
case '{':
case '}':
case '[':
case ']':
case '<':
case '>':
case '\'':
case '"':
case '$':
msg[j] = '_';
}
}
SetHdbProperty(node, eprop, msg); SetHdbProperty(node, eprop, msg);
send = NULL; send = NULL;
free(script); free(script);