$OpenBSD: patch-src_main_Rstrptime_h,v 1.1 2014/09/02 14:55:37 dcoppa Exp $

Fix stability/security issues.

--- src/main/Rstrptime.h.orig	Mon Jul 14 21:49:54 2014
+++ src/main/Rstrptime.h	Mon Jul 14 22:07:08 2014
@@ -42,6 +42,11 @@ static int locale_w_strings_set = 0;
 static void get_locale_strings(void);
 static void get_locale_w_strings(void);
 
+#define WEEKDAY_SIZE	50
+#define AB_WEEKDAY_SIZE	10
+#define MONTH_SIZE	50
+#define AB_MONTH_SIZE	10
+#define AM_PM_SIZE	10
 
 #ifdef HAVE_STRINGS_H
 #include <strings.h>  /* for strncasecmp */
@@ -93,27 +98,27 @@ static void get_locale_w_strings(void);
  * hence the extra length of the fields.
  * Some OSes (e.g. glibc) have longer than 3-char abbreviations.
  */
-static char weekday_name[][50] =
+static char weekday_name[][WEEKDAY_SIZE] =
 {
     "Sunday", "Monday", "Tuesday", "Wednesday",
     "Thursday", "Friday", "Saturday"
 };
-static char ab_weekday_name[][10] =
+static char ab_weekday_name[][AB_WEEKDAY_SIZE] =
 {
     "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
 };
-static char month_name[][50] =
+static char month_name[][MONTH_SIZE] =
 {
     "January", "February", "March", "April", "May", "June",
     "July", "August", "September", "October", "November", "December"
 };
-static char ab_month_name[][10] =
+static char ab_month_name[][AB_MONTH_SIZE] =
 {
     "Jan", "Feb", "Mar", "Apr", "May", "Jun",
     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
 };
 
-static char am_pm[][10] = {"AM", "PM"};
+static char am_pm[][AM_PM_SIZE] = {"AM", "PM"};
 
 
 # define HERE_D_T_FMT "%a %b %e %H:%M:%S %Y"
@@ -174,27 +179,27 @@ day_of_the_year (stm *tm)
 #include <wchar.h>
 #include <wctype.h>
 
-static wchar_t w_weekday_name[][50] =
+static wchar_t w_weekday_name[][WEEKDAY_SIZE] =
 {
     L"Sunday", L"Monday", L"Tuesday", L"Wednesday",
     L"Thursday", L"Friday", L"Saturday"
 };
-static wchar_t w_ab_weekday_name[][10] =
+static wchar_t w_ab_weekday_name[][AB_WEEKDAY_SIZE] =
 {
     L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat"
 };
-static wchar_t w_month_name[][50] =
+static wchar_t w_month_name[][MONTH_SIZE] =
 {
     L"January", L"February", L"March", L"April", L"May", L"June",
     L"July", L"August", L"September", L"October", L"November", L"December"
 };
-static wchar_t w_ab_month_name[][10] =
+static wchar_t w_ab_month_name[][AB_MONTH_SIZE] =
 {
     L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun",
     L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec"
 };
 
-static wchar_t w_am_pm[][10] = {L"AM", L"PM"};
+static wchar_t w_am_pm[][AM_PM_SIZE] = {L"AM", L"PM"};
 
 /* Need case-insensitive version */
 static int Rwcsncasecmp(const wchar_t *cs1, const wchar_t *s2)
@@ -1168,30 +1173,30 @@ static void get_locale_strings(void)
 {
     int i;
     struct tm tm;
-    char buff[4];
+    char buff[AM_PM_SIZE];
 
     tm.tm_sec = tm.tm_min = tm.tm_hour = tm.tm_mday = tm.tm_mon
 	= tm.tm_isdst = 0;
     tm.tm_year = 30;
     for(i = 0; i < 12; i++) {
 	tm.tm_mon = i;
-	strftime(ab_month_name[i], 10, "%b", &tm);
-	strftime(month_name[i], 50, "%B", &tm);
+	strftime(ab_month_name[i], AB_MONTH_SIZE, "%b", &tm);
+	strftime(month_name[i], MONTH_SIZE, "%B", &tm);
     }
     tm.tm_mon = 0;
     for(i = 0; i < 7; i++) {
 	tm.tm_mday = tm.tm_yday = i+1; /* 2000-1-2 was a Sunday */
 	tm.tm_wday = i;
-	strftime(ab_weekday_name[i], 10, "%a", &tm);
-	strftime(weekday_name[i], 50, "%A", &tm);
+	strftime(ab_weekday_name[i], AB_WEEKDAY_SIZE, "%a", &tm);
+	strftime(weekday_name[i], WEEKDAY_SIZE, "%A", &tm);
     }
     tm.tm_hour = 1;
     /* in locales where these are unused, they may be empty:
        better not to reset them then */
-    strftime(buff, 10, "%p", &tm);
+    strftime(buff, AM_PM_SIZE, "%p", &tm);
     if(strlen(buff)) strcpy(am_pm[0], buff);
     tm.tm_hour = 13;
-    strftime(buff, 10, "%p", &tm);
+    strftime(buff, AM_PM_SIZE, "%p", &tm);
     if(strlen(buff)) strcpy(am_pm[1], buff);
     locale_strings_set = 1;
 }
@@ -1201,30 +1206,30 @@ static void get_locale_w_strings(void)
 {
     int i;
     struct tm tm;
-    wchar_t buff[4];
+    wchar_t buff[AM_PM_SIZE];
 
     tm.tm_sec = tm.tm_min = tm.tm_hour = tm.tm_mday = tm.tm_mon
 	= tm.tm_isdst = 0;
     tm.tm_year = 30;
     for(i = 0; i < 12; i++) {
 	tm.tm_mon = i;
-	wcsftime(w_ab_month_name[i], 10, L"%b", &tm);
-	wcsftime(w_month_name[i], 50, L"%B", &tm);
+	wcsftime(w_ab_month_name[i], AB_MONTH_SIZE, L"%b", &tm);
+	wcsftime(w_month_name[i], MONTH_SIZE, L"%B", &tm);
     }
     tm.tm_mon = 0;
     for(i = 0; i < 7; i++) {
 	tm.tm_mday = tm.tm_yday = i+1; /* 2000-1-2 was a Sunday */
 	tm.tm_wday = i;
-	wcsftime(w_ab_weekday_name[i], 10, L"%a", &tm);
-	wcsftime(w_weekday_name[i], 50, L"%A", &tm);
+	wcsftime(w_ab_weekday_name[i], AB_WEEKDAY_SIZE, L"%a", &tm);
+	wcsftime(w_weekday_name[i], WEEKDAY_SIZE, L"%A", &tm);
     }
     tm.tm_hour = 1;
     /* in locales where these are unused, they may be empty:
        better not to reset them then */
-    wcsftime(buff, 10, L"%p", &tm);
+    wcsftime(buff, AM_PM_SIZE, L"%p", &tm);
     if(wcslen(buff)) wcscpy(w_am_pm[0], buff);
     tm.tm_hour = 13;
-    wcsftime(buff, 10, L"%p", &tm);
+    wcsftime(buff, AM_PM_SIZE, L"%p", &tm);
     if(wcslen(buff)) wcscpy(w_am_pm[1], buff);
     locale_w_strings_set = 1;
 }
