[Freeswitch-svn] [commit] r9985 - in freeswitch/trunk/src: . include mod/applications/mod_dptools mod/applications/mod_fifo mod/applications/mod_rss mod/applications/mod_voicemail mod/endpoints/mod_sofia mod/event_handlers/mod_cdr_csv mod/loggers/mod_logfile
Freeswitch SVN
mikej at freeswitch.org
Sun Oct 12 17:51:52 EDT 2008
Author: mikej
Date: Sun Oct 12 17:51:51 2008
New Revision: 9985
Modified:
freeswitch/trunk/src/include/switch_apr.h
freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c
freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c
freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c
freeswitch/trunk/src/mod/loggers/mod_logfile/mod_logfile.c
freeswitch/trunk/src/switch_apr.c
freeswitch/trunk/src/switch_channel.c
freeswitch/trunk/src/switch_console.c
freeswitch/trunk/src/switch_event.c
freeswitch/trunk/src/switch_log.c
freeswitch/trunk/src/switch_time.c
Log:
validate strftime format string input (when necessary)
Modified: freeswitch/trunk/src/include/switch_apr.h
==============================================================================
--- freeswitch/trunk/src/include/switch_apr.h (original)
+++ freeswitch/trunk/src/include/switch_apr.h Sun Oct 12 17:51:51 2008
@@ -271,6 +271,16 @@
SWITCH_DECLARE(switch_status_t) switch_strftime(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm);
/**
+ * formats the exploded time according to the format specified (does not validate format string)
+ * @param s string to write to
+ * @param retsize The length of the returned string
+ * @param max The maximum length of the string
+ * @param format The format for the time string
+ * @param tm The time to convert
+ */
+SWITCH_DECLARE(switch_status_t) switch_strftime_nocheck(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm);
+
+/**
* switch_rfc822_date formats dates in the RFC822
* format in an efficient manner. It is a fixed length
* format which requires the indicated amount of storage,
Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c Sun Oct 12 17:51:51 2008
@@ -1022,7 +1022,11 @@
thetime = switch_timestamp_now();
}
switch_time_exp_lt(&tm, thetime);
- switch_strftime(date, &retsize, sizeof(date), switch_strlen_zero(cmd) ? "%Y-%m-%d %T" : cmd, &tm);
+ if (switch_strlen_zero(cmd)) {
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ } else {
+ switch_strftime(date, &retsize, sizeof(date), cmd, &tm);
+ }
stream->write_function(stream, "%s", date);
return SWITCH_STATUS_SUCCESS;
Modified: freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c Sun Oct 12 17:51:51 2008
@@ -520,7 +520,7 @@
ts = switch_timestamp_now();
switch_time_exp_lt(&tm, ts);
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
switch_channel_set_variable(channel, "fifo_status", "WAITING");
switch_channel_set_variable(channel, "fifo_timestamp", date);
@@ -613,7 +613,7 @@
} else {
ts = switch_timestamp_now();
switch_time_exp_lt(&tm, ts);
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
switch_channel_set_variable(channel, "fifo_status", cd.do_orbit ? "TIMEOUT" : "ABORTED");
switch_channel_set_variable(channel, "fifo_timestamp", date);
@@ -709,7 +709,7 @@
ts = switch_timestamp_now();
switch_time_exp_lt(&tm, ts);
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
switch_channel_set_variable(channel, "fifo_status", "WAITING");
switch_channel_set_variable(channel, "fifo_timestamp", date);
@@ -883,7 +883,7 @@
ts = switch_timestamp_now();
switch_time_exp_lt(&tm, ts);
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
switch_channel_set_variable(channel, "fifo_status", "TALKING");
switch_channel_set_variable(channel, "fifo_target", uuid);
switch_channel_set_variable(channel, "fifo_timestamp", date);
@@ -910,7 +910,7 @@
ts = switch_timestamp_now();
switch_time_exp_lt(&tm, ts);
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
switch_channel_set_variable(channel, "fifo_status", "WAITING");
switch_channel_set_variable(channel, "fifo_timestamp", date);
Modified: freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c Sun Oct 12 17:51:51 2008
@@ -480,7 +480,7 @@
char dtmf[5] = "";
switch_time_exp_lt(&tm, switch_timestamp_now());
- switch_strftime(date, &retsize, sizeof(date), "%I:%M %p", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%I:%M %p", &tm);
switch_snprintf(buf, sizeof(buf),
Modified: freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c Sun Oct 12 17:51:51 2008
@@ -2728,7 +2728,7 @@
free(dbuf);
switch_time_exp_lt(&tm, ts);
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
switch_channel_set_variable(channel, "RECORD_DATE", date);
switch_channel_set_variable(channel, "RECORD_SOFTWARE", "FreeSWITCH");
switch_channel_set_variable(channel, "RECORD_TITLE", profile->record_title);
@@ -3176,13 +3176,13 @@
if (l_created) {
switch_time_exp_lt(&tm, l_created);
- switch_strftime(create_date, &retsize, sizeof(create_date), fmt, &tm);
- switch_strftime(rss_date, &retsize, sizeof(create_date), "%D %T", &tm);
+ switch_strftime_nocheck(create_date, &retsize, sizeof(create_date), fmt, &tm);
+ switch_strftime_nocheck(rss_date, &retsize, sizeof(create_date), "%D %T", &tm);
}
if (l_read) {
switch_time_exp_lt(&tm, l_read);
- switch_strftime(read_date, &retsize, sizeof(read_date), fmt, &tm);
+ switch_strftime_nocheck(read_date, &retsize, sizeof(read_date), fmt, &tm);
}
switch_snprintf(heard, sizeof(heard), *read_date == '\0' ? "never" : read_date);
@@ -3256,13 +3256,13 @@
if (l_created) {
switch_time_exp_lt(&tm, l_created);
- switch_strftime(create_date, &retsize, sizeof(create_date), fmt, &tm);
- switch_strftime(rss_date, &retsize, sizeof(create_date), fmt, &tm);
+ switch_strftime_nocheck(create_date, &retsize, sizeof(create_date), fmt, &tm);
+ switch_strftime_nocheck(rss_date, &retsize, sizeof(create_date), fmt, &tm);
}
if (l_read) {
switch_time_exp_lt(&tm, l_read);
- switch_strftime(read_date, &retsize, sizeof(read_date), fmt, &tm);
+ switch_strftime_nocheck(read_date, &retsize, sizeof(read_date), fmt, &tm);
}
holder->x_item = switch_xml_add_child_d(holder->x_channel, "item", holder->items++);
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c Sun Oct 12 17:51:51 2008
@@ -1251,7 +1251,7 @@
switch_size_t retsize;
switch_time_exp_lt(&tm, switch_time_from_sec(etime));
- switch_strftime(exp_buf, &retsize, sizeof(exp_buf), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(exp_buf, &retsize, sizeof(exp_buf), "%Y-%m-%d %T", &tm);
}
cb->stream->write_function(cb->stream,
Modified: freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c (original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c Sun Oct 12 17:51:51 2008
@@ -100,7 +100,7 @@
if (globals.rotate) {
switch_time_exp_lt(&tm, switch_timestamp_now());
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d-%H-%M-%S", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d-%H-%M-%S", &tm);
len = strlen(fd->path) + strlen(date) + 2;
p = switch_mprintf("%s.%s", fd->path, date);
Modified: freeswitch/trunk/src/mod/loggers/mod_logfile/mod_logfile.c
==============================================================================
--- freeswitch/trunk/src/mod/loggers/mod_logfile/mod_logfile.c (original)
+++ freeswitch/trunk/src/mod/loggers/mod_logfile/mod_logfile.c Sun Oct 12 17:51:51 2008
@@ -125,7 +125,7 @@
switch_mutex_lock(globals.mutex);
switch_time_exp_lt(&tm, switch_timestamp_now());
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d-%H-%M-%S", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d-%H-%M-%S", &tm);
profile->log_size = 0;
Modified: freeswitch/trunk/src/switch_apr.c
==============================================================================
--- freeswitch/trunk/src/switch_apr.c (original)
+++ freeswitch/trunk/src/switch_apr.c Sun Oct 12 17:51:51 2008
@@ -104,6 +104,57 @@
SWITCH_DECLARE(switch_status_t) switch_strftime(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm)
{
+ const char *p = format;
+
+ if (!p) return SWITCH_STATUS_FALSE;
+
+ while (*p) {
+ if (*p == '%') {
+ switch (*(++p)) {
+ case 'C':
+ case 'D':
+ case 'r':
+ case 'R':
+ case 'T':
+ case 'e':
+ case 'a':
+ case 'A':
+ case 'b':
+ case 'B':
+ case 'c':
+ case 'd':
+ case 'H':
+ case 'I':
+ case 'j':
+ case 'm':
+ case 'M':
+ case 'p':
+ case 'S':
+ case 'U':
+ case 'w':
+ case 'W':
+ case 'x':
+ case 'X':
+ case 'y':
+ case 'Y':
+ case 'z':
+ case 'Z':
+ case '%':
+ p++;
+ continue;
+ case '\0':
+ default:
+ return SWITCH_STATUS_FALSE;
+ }
+ }
+ p++;
+ }
+
+ return apr_strftime(s, retsize, max, format, (apr_time_exp_t *) tm);
+}
+
+SWITCH_DECLARE(switch_status_t) switch_strftime_nocheck(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm)
+{
return apr_strftime(s, retsize, max, format, (apr_time_exp_t *) tm);
}
Modified: freeswitch/trunk/src/switch_channel.c
==============================================================================
--- freeswitch/trunk/src/switch_channel.c (original)
+++ freeswitch/trunk/src/switch_channel.c Sun Oct 12 17:51:51 2008
@@ -2105,40 +2105,39 @@
cid_buf = caller_profile->caller_id_number;
}
-
if (caller_profile->times) {
switch_time_exp_t tm;
switch_size_t retsize;
const char *fmt = "%Y-%m-%d %T";
switch_time_exp_lt(&tm, caller_profile->times->created);
- switch_strftime(start, &retsize, sizeof(start), fmt, &tm);
+ switch_strftime_nocheck(start, &retsize, sizeof(start), fmt, &tm);
switch_channel_set_variable(channel, "start_stamp", start);
switch_time_exp_lt(&tm, caller_profile->times->profile_created);
- switch_strftime(profile_start, &retsize, sizeof(profile_start), fmt, &tm);
+ switch_strftime_nocheck(profile_start, &retsize, sizeof(profile_start), fmt, &tm);
switch_channel_set_variable(channel, "profile_start_stamp", profile_start);
if (caller_profile->times->answered) {
switch_time_exp_lt(&tm, caller_profile->times->answered);
- switch_strftime(answer, &retsize, sizeof(answer), fmt, &tm);
+ switch_strftime_nocheck(answer, &retsize, sizeof(answer), fmt, &tm);
switch_channel_set_variable(channel, "answer_stamp", answer);
}
if (caller_profile->times->progress) {
switch_time_exp_lt(&tm, caller_profile->times->progress);
- switch_strftime(progress, &retsize, sizeof(progress), fmt, &tm);
+ switch_strftime_nocheck(progress, &retsize, sizeof(progress), fmt, &tm);
switch_channel_set_variable(channel, "progress_stamp", progress);
}
if (caller_profile->times->progress_media) {
switch_time_exp_lt(&tm, caller_profile->times->progress_media);
- switch_strftime(progress_media, &retsize, sizeof(progress_media), fmt, &tm);
+ switch_strftime_nocheck(progress_media, &retsize, sizeof(progress_media), fmt, &tm);
switch_channel_set_variable(channel, "progress_media_stamp", progress_media);
}
switch_time_exp_lt(&tm, caller_profile->times->hungup);
- switch_strftime(end, &retsize, sizeof(end), fmt, &tm);
+ switch_strftime_nocheck(end, &retsize, sizeof(end), fmt, &tm);
switch_channel_set_variable(channel, "end_stamp", end);
tt_created = (time_t) (caller_profile->times->created / 1000000);
Modified: freeswitch/trunk/src/switch_console.c
==============================================================================
--- freeswitch/trunk/src/switch_console.c (original)
+++ freeswitch/trunk/src/switch_console.c Sun Oct 12 17:51:51 2008
@@ -289,7 +289,7 @@
}
switch_time_exp_lt(&tm, switch_timestamp_now());
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
if (channel == SWITCH_CHANNEL_ID_LOG) {
fprintf(handle, "[%d] %s %s:%d %s() %s", (int) getpid(), date, filep, line, func, data);
Modified: freeswitch/trunk/src/switch_event.c
==============================================================================
--- freeswitch/trunk/src/switch_event.c (original)
+++ freeswitch/trunk/src/switch_event.c Sun Oct 12 17:51:51 2008
@@ -1008,7 +1008,7 @@
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "FreeSWITCH-IPv6", guess_ip_v6);
switch_time_exp_lt(&tm, ts);
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Date-Local", date);
switch_rfc822_date(date, ts);
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Date-GMT", date);
Modified: freeswitch/trunk/src/switch_log.c
==============================================================================
--- freeswitch/trunk/src/switch_log.c (original)
+++ freeswitch/trunk/src/switch_log.c Sun Oct 12 17:51:51 2008
@@ -265,7 +265,7 @@
switch_time_exp_t tm;
switch_time_exp_lt(&tm, now);
- switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+ switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
len = (uint32_t) (strlen(extra_fmt) + strlen(date) + strlen(filep) + 32 + strlen(funcp) + strlen(fmt));
new_fmt = malloc(len + 1);
Modified: freeswitch/trunk/src/switch_time.c
==============================================================================
--- freeswitch/trunk/src/switch_time.c (original)
+++ freeswitch/trunk/src/switch_time.c Sun Oct 12 17:51:51 2008
@@ -571,7 +571,7 @@
if (tzdef) { /* The lookup of the zone may fail. */
tztime( &timep, tzdef, &tm );
tm2switchtime( &tm, &stm );
- switch_strftime(date, &retsize, len, switch_strlen_zero(format) ? "%Y-%m-%d %T" : format, &stm);
+ switch_strftime_nocheck(date, &retsize, len, switch_strlen_zero(format) ? "%Y-%m-%d %T" : format, &stm);
if (!switch_strlen_zero_buf(date)) {
return SWITCH_STATUS_SUCCESS;
}
More information about the Freeswitch-svn
mailing list