commit 87768b9d7cd9c5f938188f21b8813cdf3b3f021f
parent d993620035460719382093c242f5573df9dc9df5
Author: Colin Leroy <colin@colino.net>
Date: Sat, 20 Sep 2008 08:13:55 +0000
2008-09-20 [colin] 3.5.0cvs115
* src/common/utils.c
Fix bug 1723, "Buffer overflow crash caused by
preview in 'Date format help' dialog box"
Also, optimise fast_strftime a bit :)
Diffstat:
4 files changed, 62 insertions(+), 12 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,10 @@
+2008-09-20 [colin] 3.5.0cvs115
+
+ * src/common/utils.c
+ Fix bug 1723, "Buffer overflow crash caused by
+ preview in 'Date format help' dialog box"
+ Also, optimise fast_strftime a bit :)
+
2008-09-18 [colin] 3.5.0cvs114
* src/procmime.c
diff --git a/PATCHSETS b/PATCHSETS
@@ -3526,3 +3526,4 @@
( cvs diff -u -r 1.61.2.86 -r 1.61.2.87 src/account.c; cvs diff -u -r 1.1.2.25 -r 1.1.2.26 src/image_viewer.c; cvs diff -u -r 1.52.2.68 -r 1.52.2.69 src/prefs_folder_item.c; cvs diff -u -r 1.5.2.38 -r 1.5.2.39 src/prefs_spelling.c; cvs diff -u -r 1.9.2.62 -r 1.9.2.63 src/gtk/gtkaspell.c; ) > 3.5.0cvs112.patchset
( cvs diff -u -r 1.94.2.186 -r 1.94.2.187 src/messageview.c; cvs diff -u -r 1.49.2.115 -r 1.49.2.116 src/procmime.c; cvs diff -u -r 1.96.2.206 -r 1.96.2.207 src/textview.c; cvs diff -u -r 1.1.4.32 -r 1.1.4.33 src/gtk/logwindow.c; cvs diff -u -r 1.1.4.15 -r 1.1.4.16 src/gtk/logwindow.h; ) > 3.5.0cvs113.patchset
( cvs diff -u -r 1.49.2.116 -r 1.49.2.117 src/procmime.c; cvs diff -u -r 1.96.2.207 -r 1.96.2.208 src/textview.c; ) > 3.5.0cvs114.patchset
+( cvs diff -u -r 1.36.2.146 -r 1.36.2.147 src/common/utils.c; ) > 3.5.0cvs115.patchset
diff --git a/configure.ac b/configure.ac
@@ -11,7 +11,7 @@ MINOR_VERSION=5
MICRO_VERSION=0
INTERFACE_AGE=0
BINARY_AGE=0
-EXTRA_VERSION=114
+EXTRA_VERSION=115
EXTRA_RELEASE=
EXTRA_GTK2_VERSION=
diff --git a/src/common/utils.c b/src/common/utils.c
@@ -184,6 +184,18 @@ gint g_chmod(const gchar *path, gint mode)
return chmod(path, mode);
#endif
}
+
+FILE* g_fopen(const gchar *filename, const gchar *mode)
+{
+#ifdef G_OS_WIN32
+ char *name = g_win32_locale_filename_from_utf8(filename);
+ FILE* fp = fopen(name, mode);
+ g_free(name);
+ return fp;
+#else
+ return fopen(filename, mode);
+#endif
+}
#endif /* GLIB_CHECK_VERSION && G_OS_UNIX */
@@ -4759,10 +4771,23 @@ const gchar *monthnames[] = {NULL, NULL, NULL, NULL, NULL, NULL,
const gchar *s_daynames[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
const gchar *s_monthnames[] = {NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL};
+
+gint daynames_len[] = {0,0,0,0,0,0,0};
+gint monthnames_len[] = {0,0,0,0,0,0,
+ 0,0,0,0,0,0};
+gint s_daynames_len[] = {0,0,0,0,0,0,0};
+gint s_monthnames_len[] = {0,0,0,0,0,0,
+ 0,0,0,0,0,0};
const gchar *s_am_up = NULL;
const gchar *s_pm_up = NULL;
const gchar *s_am_low = NULL;
const gchar *s_pm_low = NULL;
+
+gint s_am_up_len = 0;
+gint s_pm_up_len = 0;
+gint s_am_low_len = 0;
+gint s_pm_low_len = 0;
+
const gchar *def_loc_format = NULL;
const gchar *date_loc_format = NULL;
const gchar *time_loc_format = NULL;
@@ -4772,6 +4797,8 @@ static gboolean time_names_init_done = FALSE;
static void init_time_names(void)
{
+ int i = 0;
+
daynames[0] = Q_("Complete day name for use by strftime|Sunday");
daynames[1] = Q_("Complete day name for use by strftime|Monday");
daynames[2] = Q_("Complete day name for use by strftime|Tuesday");
@@ -4779,7 +4806,7 @@ static void init_time_names(void)
daynames[4] = Q_("Complete day name for use by strftime|Thursday");
daynames[5] = Q_("Complete day name for use by strftime|Friday");
daynames[6] = Q_("Complete day name for use by strftime|Saturday");
-
+
monthnames[0] = Q_("Complete month name for use by strftime|January");
monthnames[1] = Q_("Complete month name for use by strftime|February");
monthnames[2] = Q_("Complete month name for use by strftime|March");
@@ -4814,11 +4841,25 @@ static void init_time_names(void)
s_monthnames[10] = Q_("Abbr. month name for use by strftime|Nov");
s_monthnames[11] = Q_("Abbr. month name for use by strftime|Dec");
+ for (i = 0; i < 7; i++) {
+ daynames_len[i] = strlen(daynames[i]);
+ s_daynames_len[i] = strlen(s_daynames[i]);
+ }
+ for (i = 0; i < 12; i++) {
+ monthnames_len[i] = strlen(monthnames[i]);
+ s_monthnames_len[i] = strlen(s_monthnames[i]);
+ }
+
s_am_up = Q_("For use by strftime (morning)|AM");
s_pm_up = Q_("For use by strftime (afternoon)|PM");
s_am_low = Q_("For use by strftime (morning, lowercase)|am");
s_pm_low = Q_("For use by strftime (afternoon, lowercase)|pm");
+ s_am_up_len = strlen(s_am_up);
+ s_pm_up_len = strlen(s_pm_up);
+ s_am_low_len = strlen(s_am_low);
+ s_pm_low_len = strlen(s_pm_low);
+
def_loc_format = Q_("For use by strftime (default date+time format)|%a %b %e %H:%M:%S %Y");
date_loc_format = Q_("For use by strftime (default date format)|%m/%d/%y");
time_loc_format = Q_("For use by strftime (default time format)|%H:%M:%S");
@@ -4863,20 +4904,20 @@ size_t fast_strftime(gchar *buf, gint buflen, const gchar *format, struct tm *lt
*curpos = '%';
break;
case 'a':
- len = strlen(s_daynames[lt->tm_wday]); CHECK_SIZE();
+ len = s_daynames_len[lt->tm_wday]; CHECK_SIZE();
strncpy2(curpos, s_daynames[lt->tm_wday], buflen - total_done);
break;
case 'A':
- len = strlen(daynames[lt->tm_wday]); CHECK_SIZE();
+ len = daynames_len[lt->tm_wday]; CHECK_SIZE();
strncpy2(curpos, daynames[lt->tm_wday], buflen - total_done);
break;
case 'b':
case 'h':
- len = strlen(s_monthnames[lt->tm_mon]); CHECK_SIZE();
+ len = s_monthnames_len[lt->tm_mon]; CHECK_SIZE();
strncpy2(curpos, s_monthnames[lt->tm_mon], buflen - total_done);
break;
case 'B':
- len = strlen(monthnames[lt->tm_mon]); CHECK_SIZE();
+ len = monthnames_len[lt->tm_mon]; CHECK_SIZE();
strncpy2(curpos, monthnames[lt->tm_mon], buflen - total_done);
break;
case 'c':
@@ -4965,19 +5006,19 @@ size_t fast_strftime(gchar *buf, gint buflen, const gchar *format, struct tm *lt
break;
case 'p':
if (lt->tm_hour >= 12) {
- len = strlen(s_pm_up); CHECK_SIZE();
+ len = s_pm_up_len; CHECK_SIZE();
snprintf(curpos, buflen-total_done, "%s", s_pm_up);
} else {
- len = strlen(s_am_up); CHECK_SIZE();
+ len = s_am_up_len; CHECK_SIZE();
snprintf(curpos, buflen-total_done, "%s", s_am_up);
}
break;
case 'P':
if (lt->tm_hour >= 12) {
- len = strlen(s_pm_low); CHECK_SIZE();
+ len = s_pm_low_len; CHECK_SIZE();
snprintf(curpos, buflen-total_done, "%s", s_pm_low);
} else {
- len = strlen(s_am_low); CHECK_SIZE();
+ len = s_am_low_len; CHECK_SIZE();
snprintf(curpos, buflen-total_done, "%s", s_am_low);
}
break;
@@ -4995,7 +5036,7 @@ size_t fast_strftime(gchar *buf, gint buflen, const gchar *format, struct tm *lt
*curpos++ = '0'+(lt->tm_min % 10);
break;
case 's':
- snprintf(subbuf, buflen - total_done, "%ld", mktime(lt));
+ snprintf(subbuf, 64, "%ld", mktime(lt));
len = strlen(subbuf); CHECK_SIZE();
strncpy2(curpos, subbuf, buflen - total_done);
break;
@@ -5071,7 +5112,8 @@ size_t fast_strftime(gchar *buf, gint buflen, const gchar *format, struct tm *lt
format++;
break;
default:
- g_warning("format error (%c)", *format);
+ if (format && *format)
+ g_warning("format error (%c)", *format);
*curpos = '\0';
return total_done;
}