提交 964aec99 authored 作者: Michael Jerris's avatar Michael Jerris

make logger handle a bit more bad input.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3306 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 2a645dbc
......@@ -169,7 +169,8 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, char *file
int ret = 0;
va_list ap;
FILE *handle;
char *filep = switch_cut_path(file);
char *filep = (file ? switch_cut_path(file): "");
const char *funcp = (func ? func : "");
char *content = NULL;
switch_time_t now = switch_time_now();
uint32_t len;
......@@ -186,9 +187,9 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, char *file
switch_time_exp_lt(&tm, now);
switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
len = (uint32_t)(strlen(extra_fmt) + strlen(date) + strlen(filep) + 32 + strlen(func) + strlen(fmt));
len = (uint32_t)(strlen(extra_fmt) + strlen(date) + strlen(filep) + 32 + strlen(funcp) + strlen(fmt));
new_fmt = malloc(len+1);
snprintf(new_fmt, len, extra_fmt, date, LEVELS[level], filep, line, func, 128, fmt);
snprintf(new_fmt, len, extra_fmt, date, LEVELS[level], filep, line, funcp, 128, fmt);
fmt = new_fmt;
}
......@@ -216,7 +217,7 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, char *file
if (switch_event_running() == SWITCH_STATUS_SUCCESS && switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Data", "%s", data);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-File", "%s", filep);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Function", "%s", func);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Function", "%s", funcp);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Line", "%d", line);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Level", "%d", (int)level);
switch_event_fire(&event);
......@@ -231,7 +232,7 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, char *file
if ((node = malloc(sizeof(*node)))) {
node->data = data;
node->file = strdup(filep);
node->func = strdup(func);
node->func = strdup(funcp);
node->line = line;
node->level = level;
node->content = content;
......
......@@ -167,6 +167,7 @@ SWITCH_DECLARE(char *) switch_cut_path(char *in)
char delims[] = "/\\";
char *i;
if (in) {
for (i = delims; *i; i++) {
p = in;
while ((p = strchr(p, *i)) != 0) {
......@@ -174,6 +175,9 @@ SWITCH_DECLARE(char *) switch_cut_path(char *in)
}
}
return ret;
} else {
return NULL;
}
}
SWITCH_DECLARE(switch_status_t) switch_socket_create_pollfd(switch_pollfd_t *poll, switch_socket_t *sock,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论