aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormogorman <mogorman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-11-11 02:04:28 +0000
committermogorman <mogorman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-11-11 02:04:28 +0000
commitb87d94c31bdc998e41f7a6c3f64f41e2df35dfbe (patch)
treed75924644e33600c2aabdd0d543678361fa1a9a9
parent38cb750018aef13dcfe28b61c248e4f325a6f741 (diff)
woohoo safe out put!
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@47490 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--include/asterisk/term.h2
-rw-r--r--main/logger.c10
-rw-r--r--main/term.c28
3 files changed, 38 insertions, 2 deletions
diff --git a/include/asterisk/term.h b/include/asterisk/term.h
index f3c41d8eb..3b454ce2c 100644
--- a/include/asterisk/term.h
+++ b/include/asterisk/term.h
@@ -59,6 +59,8 @@ char *term_color_code(char *outbuf, int fgcolor, int bgcolor, int maxout);
char *term_strip(char *outbuf, char *inbuf, int maxout);
+void term_filter_escapes(char *line);
+
char *term_prompt(char *outbuf, const char *inbuf, int maxout);
char *term_prep(void);
diff --git a/main/logger.c b/main/logger.c
index 2eaa04a8f..21effac71 100644
--- a/main/logger.c
+++ b/main/logger.c
@@ -700,8 +700,10 @@ void ast_log(int level, const char *file, int line, const char *function, const
va_start(ap, fmt);
res = ast_dynamic_str_thread_set_va(&buf, BUFSIZ, &log_buf, fmt, ap);
va_end(ap);
- if (res != AST_DYNSTR_BUILD_FAILED)
+ if (res != AST_DYNSTR_BUILD_FAILED) {
+ term_filter_escapes(buf->str);
fputs(buf->str, stdout);
+ }
}
return;
}
@@ -765,7 +767,8 @@ void ast_log(int level, const char *file, int line, const char *function, const
term_color(tmp2, file, COLOR_BRWHITE, 0, sizeof(tmp2)),
term_color(tmp3, linestr, COLOR_BRWHITE, 0, sizeof(tmp3)),
term_color(tmp4, function, COLOR_BRWHITE, 0, sizeof(tmp4)));
-
+ /*filter to the console!*/
+ term_filter_escapes(buf->str);
ast_console_puts_mutable(buf->str);
va_start(ap, fmt);
@@ -873,6 +876,9 @@ void ast_verbose(const char *fmt, ...)
if (res == AST_DYNSTR_BUILD_FAILED)
return;
+
+ /* filter out possibly hazardous escape sequences */
+ term_filter_escapes(buf->str);
AST_LIST_LOCK(&verbosers);
AST_LIST_TRAVERSE(&verbosers, v, list)
diff --git a/main/term.c b/main/term.c
index a38399eda..e92a27077 100644
--- a/main/term.c
+++ b/main/term.c
@@ -264,6 +264,34 @@ char *term_prompt(char *outbuf, const char *inbuf, int maxout)
return outbuf;
}
+
+/* filter escape sequences */
+void term_filter_escapes(char *line)
+ {
+ int i;
+
+ for (i=0; i < strlen(line); i++) {
+ if (line[i] == ESC) {
+ if (line[i+1] == '\x5b') {
+ switch (line[i+2]) {
+ case '\x30':
+ break;
+ case '\x31':
+ break;
+ case '\x33':
+ break;
+ default:
+ /* replace ESC with a space */
+ line[i] = ' ';
+ }
+ } else {
+ /* replace ESC with a space */
+ line[i] = ' ';
+ }
+ }
+ }
+ }
+
char *term_prep(void)
{
return prepdata;