]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
make logger handle a bit more bad input.
authorMichael Jerris <mike@jerris.com>
Fri, 10 Nov 2006 16:30:02 +0000 (16:30 +0000)
committerMichael Jerris <mike@jerris.com>
Fri, 10 Nov 2006 16:30:02 +0000 (16:30 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3306 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/switch_log.c
src/switch_utils.c

index 4087913cca0dbbc235f9ec3d3cbcf6661e53fb68..257e4c1687185da2f9d3564993dcfea770a248d0 100644 (file)
@@ -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;
index 965f4397dd532d5e1cc30926e82eb0645400ec91..998c1854c5300ae20ef795630358b95e919fa7d6 100644 (file)
@@ -167,13 +167,17 @@ SWITCH_DECLARE(char *) switch_cut_path(char *in)
        char delims[] = "/\\";
        char *i;
 
-       for (i = delims; *i; i++) {
-               p = in;
-               while ((p = strchr(p, *i)) != 0) {
-                       ret = ++p;
+       if (in) {
+               for (i = delims; *i; i++) {
+                       p = in;
+                       while ((p = strchr(p, *i)) != 0) {
+                               ret = ++p;
+                       }
                }
+               return ret;
+       } else {
+               return NULL;
        }
-       return ret;
 }
 
 SWITCH_DECLARE(switch_status_t) switch_socket_create_pollfd(switch_pollfd_t *poll, switch_socket_t *sock,