validate strftime format string input (when necessary)

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9985 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris committed 2008-10-12 21:51:51 +00:00
1 parent a21b5ed2ad
commit 1f47ff15b3
14 files changed
+92 -28

No files matched your search

+51
View File
@@ -103,6 +103,57 @@ SWITCH_DECLARE(const char *) switch_dso_error(switch_dso_handle_t *dso, char *bu
/* string functions */
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);
}