* persistantly handle the bufferlengths for dates; snprintf doesn't terminate strings...
authorWilfried Göesgens <willi@citadel.org>
Sat, 18 Apr 2009 12:14:27 +0000 (12:14 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 18 Apr 2009 12:14:27 +0000 (12:14 +0000)
webcit/calendar.c
webcit/calendar_view.c
webcit/fmt_date.c
webcit/msg_renderers.c
webcit/smtpqueue.c
webcit/webcit.h

index 8b95638048bdc28f2018eabec15305b468285678..8808618c06f2b4448c19e929acb275a5d2cd20ef 100644 (file)
@@ -125,7 +125,7 @@ void cal_process_object(StrBuf *Target,
                        }
                        else {
                                tt = icaltime_as_timet(t);
-                               webcit_fmt_date(buf, tt, DATEFMT_FULL);
+                               webcit_fmt_date(buf, 256, tt, DATEFMT_FULL);
                                StrBufAppendPrintf(Target, "<dt>");
                                StrBufAppendPrintf(Target, _("Starting date/time:"));
                                StrBufAppendPrintf(Target, "</dt><dd>%s</dd>", buf);
@@ -136,7 +136,7 @@ void cal_process_object(StrBuf *Target,
                if (p != NULL) {
                        t = icalproperty_get_dtend(p);
                        tt = icaltime_as_timet(t);
-                       webcit_fmt_date(buf, tt, DATEFMT_FULL);
+                       webcit_fmt_date(buf, 256, tt, DATEFMT_FULL);
                        StrBufAppendPrintf(Target, "<dt>");
                        StrBufAppendPrintf(Target, _("Ending date/time:"));
                        StrBufAppendPrintf(Target, "</dt><dd>%s</dd>", buf);
index 41a03ac395a5dd1e0aaadf5a35ed665188d2209e..6d71049a9b406e8120eb57017ad6220daa9a5a24 100644 (file)
@@ -335,7 +335,7 @@ void calendar_month_view_display_events(int year, int month, int day)
                                                }
                                                else {
                                                        tt = icaltime_as_timet(t);
-                                                       webcit_fmt_date(buf, tt, DATEFMT_BRIEF);
+                                                       webcit_fmt_date(buf, 256, tt, DATEFMT_BRIEF);
                                                        if (no_end || !icaltime_compare(t, end_t)) {
                                                                wprintf("<i>%s</i> %s<br>",
                                                                        _("Date/time:"), buf);
@@ -344,7 +344,7 @@ void calendar_month_view_display_events(int year, int month, int day)
                                                                wprintf("<i>%s</i> %s<br>",
                                                                        _("Starting date/time:"), buf);
                                                                tt = icaltime_as_timet(end_t);
-                                                               webcit_fmt_date(buf, tt, DATEFMT_BRIEF);
+                                                               webcit_fmt_date(buf, 256, tt, DATEFMT_BRIEF);
                                                                wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
                                                        }
                                                        
@@ -946,13 +946,13 @@ void calendar_day_view_display_events(time_t thetime,
                                         wprintf("<br />");
                                }
                                if (!icaltime_compare(t, end_t)) { /* one day only */
-                                       webcit_fmt_date(buf, event_tt, DATEFMT_LOCALEDATE);
+                                       webcit_fmt_date(buf, 256, event_tt, DATEFMT_LOCALEDATE);
                                        wprintf("<i>%s</i> %s<br>", _("Date:"), buf);
                                }
                                else {
-                                       webcit_fmt_date(buf, event_tt, DATEFMT_LOCALEDATE);
+                                       webcit_fmt_date(buf, 256, event_tt, DATEFMT_LOCALEDATE);
                                        wprintf("<i>%s</i> %s<br>", _("Starting date:"), buf);
-                                       webcit_fmt_date(buf, event_tte, DATEFMT_LOCALEDATE);
+                                       webcit_fmt_date(buf, 256, event_tte, DATEFMT_LOCALEDATE);
                                        wprintf("<i>%s</i> %s<br>", _("Ending date:"), buf);
                                }
                                q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
@@ -987,9 +987,9 @@ void calendar_day_view_display_events(time_t thetime,
                                         escputs((char *)icalproperty_get_comment(q));
                                         wprintf("<br />");
                                                                }
-                                webcit_fmt_date(buf, event_tt, DATEFMT_BRIEF);
+                                webcit_fmt_date(buf, 256, event_tt, DATEFMT_BRIEF);
                                 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
-                                webcit_fmt_date(buf, event_tte, DATEFMT_BRIEF);
+                                webcit_fmt_date(buf, 256, event_tte, DATEFMT_BRIEF);
                                 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
                                 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
                                 if (q) {
@@ -1067,13 +1067,13 @@ void calendar_day_view_display_events(time_t thetime,
                                         wprintf("<br />");
                                                                }
                                if (!icaltime_compare(t, end_t)) { /* one day only */
-                                       webcit_fmt_date(buf, event_tt, DATEFMT_BRIEF);
+                                       webcit_fmt_date(buf, 256, event_tt, DATEFMT_BRIEF);
                                        wprintf("<i>%s</i> %s<br>", _("Date/time:"), buf);
                                }
                                else {
-                                       webcit_fmt_date(buf, event_tt, DATEFMT_BRIEF);
+                                       webcit_fmt_date(buf, 256, event_tt, DATEFMT_BRIEF);
                                        wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
-                                       webcit_fmt_date(buf, event_tte, DATEFMT_BRIEF);
+                                       webcit_fmt_date(buf, 256, event_tte, DATEFMT_BRIEF);
                                        wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
                                }
                                q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
@@ -1359,7 +1359,7 @@ int calendar_summary_view(void) {
                        else {
                                all_day_event = 0;
                        }
-                       fmt_time(timestring, event_tt);
+                       fmt_time(timestring, SIZ, event_tt);
 
                        if (all_day_event) {
                                gmtime_r(&event_tt, &event_tm);
@@ -1659,7 +1659,7 @@ void do_tasks_view(void) {
                due = get_task_due_date(Cal->cal, &is_date);
                wprintf("<td><span");
                if (due > 0) {
-                       webcit_fmt_date(buf, due, is_date ? DATEFMT_RAWDATE : DATEFMT_FULL);
+                       webcit_fmt_date(buf, SIZ, due, is_date ? DATEFMT_RAWDATE : DATEFMT_FULL);
                        wprintf(">%s",buf);
                }
                else {
index ecc7b78bbb9fbcf7470bfb349c9ffe6ac408c1df..40419ac2e920744e091bf04e8515647477da6305 100644 (file)
@@ -47,7 +47,7 @@ size_t wc_strftime(char *s, size_t max, const char *format, const struct tm *tm)
 /*
  * Format a date/time stamp for output 
  */
-void webcit_fmt_date(char *buf, time_t thetime, int Format)
+void webcit_fmt_date(char *buf, size_t siz, time_t thetime, int Format)
 {
        struct tm tm;
        struct tm today_tm;
@@ -76,31 +76,31 @@ void webcit_fmt_date(char *buf, time_t thetime, int Format)
                          &&(tm.tm_mon == today_tm.tm_mon)
                          &&(tm.tm_mday == today_tm.tm_mday)) {
                                if (time_format == WC_TIMEFORMAT_24) 
-                                       wc_strftime(buf, 32, "%k:%M", &tm);
+                                       wc_strftime(buf, siz, "%k:%M", &tm);
                                else
-                                       wc_strftime(buf, 32, "%l:%M%p", &tm);
+                                       wc_strftime(buf, siz, "%l:%M%p", &tm);
                        }
                        else if (today_timet - thetime < 15552000) {
                                if (time_format == WC_TIMEFORMAT_24) 
-                                       wc_strftime(buf, 32, "%b %d %k:%M", &tm);
+                                       wc_strftime(buf, siz, "%b %d %k:%M", &tm);
                                else
-                                       wc_strftime(buf, 32, "%b %d %l:%M%p", &tm);
+                                       wc_strftime(buf, siz, "%b %d %l:%M%p", &tm);
                        }
                        else {
-                               wc_strftime(buf, 32, "%b %d %Y", &tm);
+                               wc_strftime(buf, siz, "%b %d %Y", &tm);
                        }
                        break;
                case DATEFMT_FULL:
                        if (time_format == WC_TIMEFORMAT_24)
-                               wc_strftime(buf, 32, "%a %b %d %Y %T %Z", &tm);
+                               wc_strftime(buf, siz, "%a %b %d %Y %T %Z", &tm);
                        else
-                               wc_strftime(buf, 32, "%a %b %d %Y %r %Z", &tm);
+                               wc_strftime(buf, siz, "%a %b %d %Y %r %Z", &tm);
                        break;
                case DATEFMT_RAWDATE:
-                       wc_strftime(buf, 32, "%a %b %d %Y", &tm);
+                       wc_strftime(buf, siz, "%a %b %d %Y", &tm);
                        break;
                case DATEFMT_LOCALEDATE:
-                       wc_strftime(buf, 32, "%x", &tm);
+                       wc_strftime(buf, siz, "%x", &tm);
                        break;
        }
 }
@@ -110,10 +110,10 @@ void webcit_fmt_date(char *buf, time_t thetime, int Format)
  * Try to guess whether the user will prefer 12 hour or 24 hour time based on the locale.
  */
 long guess_calhourformat(void) {
-       char buf[32];
+       char buf[64];
        struct tm tm;
        memset(&tm, 0, sizeof tm);
-       wc_strftime(buf, 32, "%X", &tm);
+       wc_strftime(buf, 64, "%X", &tm);
        if (buf[strlen(buf)-1] == 'M') {
                return 12;
        }
@@ -154,7 +154,7 @@ int get_time_format_cached (void)
  * buf         the output buffer
  * thetime     time to format into buf
  */
-void fmt_time(char *buf, time_t thetime)
+void fmt_time(char *buf, size_t siz, time_t thetime)
 {
        struct tm *tm;
        int hour;
@@ -170,12 +170,12 @@ void fmt_time(char *buf, time_t thetime)
                hour = hour - 12;
 
        if (time_format == WC_TIMEFORMAT_24) {
-               sprintf(buf, "%d:%02d",
+               snprintf(buf, siz, "%d:%02d",
                        tm->tm_hour, tm->tm_min
                );
        }
        else {
-               sprintf(buf, "%d:%02d%s",
+               snprintf(buf, siz, "%d:%02d%s",
                        hour, tm->tm_min, ((tm->tm_hour > 12) ? "pm" : "am")
                );
        }
index b401ea7595a6dc6f1aa0f545e6fd935a18c1e3cb..5481cdcebfea03c35a0610ea3cd63e534f0d8acd 100644 (file)
@@ -441,7 +441,7 @@ void tmplput_MAIL_SUMM_DATE_BRIEF(StrBuf *Target, WCTemplputParams *TP)
 {
        char datebuf[64];
        message_summary *Msg = (message_summary*) CTX;
-       webcit_fmt_date(datebuf, Msg->date, DATEFMT_BRIEF);
+       webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_BRIEF);
        StrBufAppendBufPlain(Target, datebuf, -1, 0);
 }
 
@@ -449,13 +449,13 @@ void tmplput_MAIL_SUMM_DATE_FULL(StrBuf *Target, WCTemplputParams *TP)
 {
        char datebuf[64];
        message_summary *Msg = (message_summary*) CTX;
-       webcit_fmt_date(datebuf, Msg->date, DATEFMT_FULL);
+       webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_FULL);
        StrBufAppendBufPlain(Target, datebuf, -1, 0);
 }
 void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, WCTemplputParams *TP)
 {
        message_summary *Msg = (message_summary*) CTX;
-       StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
+       StrBufAppendPrintf(Target, 64, "%ld", Msg->date, 0);
 }
 
 
index 43f5cd90ac064ecb079d0e622a008766d52fd9c5..db7e4c19f0234b63baa6bba8d6fba60bb12525c2 100644 (file)
@@ -137,7 +137,7 @@ void display_queue_msg(long msgnum)
 
        wprintf("</td><td>");
        if (submitted > 0) {
-               webcit_fmt_date(buf, submitted, 1);
+               webcit_fmt_date(buf, 1024, submitted, 1);
                wprintf("%s", buf);
        }
        else {
@@ -146,7 +146,7 @@ void display_queue_msg(long msgnum)
 
        wprintf("</td><td>");
        if (last_attempt > 0) {
-               webcit_fmt_date(buf, last_attempt, 1);
+               webcit_fmt_date(buf, 1024, last_attempt, 1);
                wprintf("%s", buf);
        }
        else {
index 832ed0dc6114778caaebd00aeb2bdc33599c2133..90404821dd92b6403b38be60dd6e5b72c202d52b 100644 (file)
@@ -623,7 +623,7 @@ void smart_goto(const StrBuf *);
 void worker_entry(void);
 void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *ReqType, StrBuf *ReadBuf);
 size_t wc_strftime(char *s, size_t max, const char *format, const struct tm *tm);
-void fmt_time(char *buf, time_t thetime);
+void fmt_time(char *buf, size_t siz, time_t thetime);
 void httpdate(char *buf, time_t thetime);
 time_t httpdate_to_timestamp(StrBuf *buf);
 void end_webcit_session(void);
@@ -643,8 +643,6 @@ char *load_mimepart(long msgnum, char *partnum);
 void MimeLoadData(wc_mime_attachment *Mime);
 int pattern2(char *search, char *patn);
 void do_edit_vcard(long, char *, char *, const char *);
-void striplt(char *);
-void stripltlen(char *, int *);
 void select_user_to_edit(char *message, char *preselect);
 void delete_user(char *);
 void do_change_view(int);
@@ -733,7 +731,7 @@ const char *get_selected_language(void);
 #define DATEFMT_BRIEF 1
 #define DATEFMT_RAWDATE 2
 #define DATEFMT_LOCALEDATE 3
-void webcit_fmt_date(char *buf, time_t thetime, int Format);
+void webcit_fmt_date(char *buf, size_t siz, time_t thetime, int Format);
 int fetch_http(char *url, char *target_buf, int maxbytes);
 void free_attachments(wcsession *sess);
 void summary(void);