110
110
* Maximal length of one node
111
111
* ----------
112
112
*/
113
- #define DCH_MAX_ITEM_SIZ 9 /* max julian day */
113
+ #define DCH_MAX_ITEM_SIZ 12 /* max localized day name */
114
114
#define NUM_MAX_ITEM_SIZ 8 /* roman number (RN has 15 chars) */
115
115
116
116
/* ----------
@@ -518,10 +518,12 @@ do { \
518
518
* Suffixes definition for DATE-TIME TO/FROM CHAR
519
519
* ----------
520
520
*/
521
+ #define TM_SUFFIX_LEN 2
522
+
521
523
static const KeySuffix DCH_suff [] = {
522
524
{"FM" , 2 , DCH_S_FM , SUFFTYPE_PREFIX },
523
525
{"fm" , 2 , DCH_S_FM , SUFFTYPE_PREFIX },
524
- {"TM" , 2 , DCH_S_TM , SUFFTYPE_PREFIX },
526
+ {"TM" , TM_SUFFIX_LEN , DCH_S_TM , SUFFTYPE_PREFIX },
525
527
{"tm" , 2 , DCH_S_TM , SUFFTYPE_PREFIX },
526
528
{"TH" , 2 , DCH_S_TH , SUFFTYPE_POSTFIX },
527
529
{"th" , 2 , DCH_S_th , SUFFTYPE_POSTFIX },
@@ -530,6 +532,7 @@ static const KeySuffix DCH_suff[] = {
530
532
{NULL , 0 , 0 , 0 }
531
533
};
532
534
535
+
533
536
/* ----------
534
537
* Format-pictures (KeyWord).
535
538
*
@@ -2537,7 +2540,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2537
2540
if (!tm -> tm_mon )
2538
2541
break ;
2539
2542
if (S_TM (n -> suffix ))
2540
- strcpy (s , str_toupper_z (localized_full_months [tm -> tm_mon - 1 ], collid ));
2543
+ {
2544
+ char * str = str_toupper_z (localized_full_months [tm -> tm_mon - 1 ], collid );
2545
+
2546
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2547
+ strcpy (s , str );
2548
+ else
2549
+ ereport (ERROR ,
2550
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2551
+ errmsg ("localized string format value too long" )));
2552
+ }
2541
2553
else
2542
2554
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2543
2555
asc_toupper_z (months_full [tm -> tm_mon - 1 ]));
@@ -2548,7 +2560,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2548
2560
if (!tm -> tm_mon )
2549
2561
break ;
2550
2562
if (S_TM (n -> suffix ))
2551
- strcpy (s , str_initcap_z (localized_full_months [tm -> tm_mon - 1 ], collid ));
2563
+ {
2564
+ char * str = str_initcap_z (localized_full_months [tm -> tm_mon - 1 ], collid );
2565
+
2566
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2567
+ strcpy (s , str );
2568
+ else
2569
+ ereport (ERROR ,
2570
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2571
+ errmsg ("localized string format value too long" )));
2572
+ }
2552
2573
else
2553
2574
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2554
2575
months_full [tm -> tm_mon - 1 ]);
@@ -2559,7 +2580,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2559
2580
if (!tm -> tm_mon )
2560
2581
break ;
2561
2582
if (S_TM (n -> suffix ))
2562
- strcpy (s , str_tolower_z (localized_full_months [tm -> tm_mon - 1 ], collid ));
2583
+ {
2584
+ char * str = str_tolower_z (localized_full_months [tm -> tm_mon - 1 ], collid );
2585
+
2586
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2587
+ strcpy (s , str );
2588
+ else
2589
+ ereport (ERROR ,
2590
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2591
+ errmsg ("localized string format value too long" )));
2592
+ }
2563
2593
else
2564
2594
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2565
2595
asc_tolower_z (months_full [tm -> tm_mon - 1 ]));
@@ -2570,7 +2600,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2570
2600
if (!tm -> tm_mon )
2571
2601
break ;
2572
2602
if (S_TM (n -> suffix ))
2573
- strcpy (s , str_toupper_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid ));
2603
+ {
2604
+ char * str = str_toupper_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid );
2605
+
2606
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2607
+ strcpy (s , str );
2608
+ else
2609
+ ereport (ERROR ,
2610
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2611
+ errmsg ("localized string format value too long" )));
2612
+ }
2574
2613
else
2575
2614
strcpy (s , asc_toupper_z (months [tm -> tm_mon - 1 ]));
2576
2615
s += strlen (s );
@@ -2580,7 +2619,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2580
2619
if (!tm -> tm_mon )
2581
2620
break ;
2582
2621
if (S_TM (n -> suffix ))
2583
- strcpy (s , str_initcap_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid ));
2622
+ {
2623
+ char * str = str_initcap_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid );
2624
+
2625
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2626
+ strcpy (s , str );
2627
+ else
2628
+ ereport (ERROR ,
2629
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2630
+ errmsg ("localized string format value too long" )));
2631
+ }
2584
2632
else
2585
2633
strcpy (s , months [tm -> tm_mon - 1 ]);
2586
2634
s += strlen (s );
@@ -2590,7 +2638,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2590
2638
if (!tm -> tm_mon )
2591
2639
break ;
2592
2640
if (S_TM (n -> suffix ))
2593
- strcpy (s , str_tolower_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid ));
2641
+ {
2642
+ char * str = str_tolower_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid );
2643
+
2644
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2645
+ strcpy (s , str );
2646
+ else
2647
+ ereport (ERROR ,
2648
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2649
+ errmsg ("localized string format value too long" )));
2650
+ }
2594
2651
else
2595
2652
strcpy (s , asc_tolower_z (months [tm -> tm_mon - 1 ]));
2596
2653
s += strlen (s );
@@ -2604,7 +2661,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2604
2661
case DCH_DAY :
2605
2662
INVALID_FOR_INTERVAL ;
2606
2663
if (S_TM (n -> suffix ))
2607
- strcpy (s , str_toupper_z (localized_full_days [tm -> tm_wday ], collid ));
2664
+ {
2665
+ char * str = str_toupper_z (localized_full_days [tm -> tm_wday ], collid );
2666
+
2667
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2668
+ strcpy (s , str );
2669
+ else
2670
+ ereport (ERROR ,
2671
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2672
+ errmsg ("localized string format value too long" )));
2673
+ }
2608
2674
else
2609
2675
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2610
2676
asc_toupper_z (days [tm -> tm_wday ]));
@@ -2613,7 +2679,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2613
2679
case DCH_Day :
2614
2680
INVALID_FOR_INTERVAL ;
2615
2681
if (S_TM (n -> suffix ))
2616
- strcpy (s , str_initcap_z (localized_full_days [tm -> tm_wday ], collid ));
2682
+ {
2683
+ char * str = str_initcap_z (localized_full_days [tm -> tm_wday ], collid );
2684
+
2685
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2686
+ strcpy (s , str );
2687
+ else
2688
+ ereport (ERROR ,
2689
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2690
+ errmsg ("localized string format value too long" )));
2691
+ }
2617
2692
else
2618
2693
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2619
2694
days [tm -> tm_wday ]);
@@ -2622,7 +2697,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2622
2697
case DCH_day :
2623
2698
INVALID_FOR_INTERVAL ;
2624
2699
if (S_TM (n -> suffix ))
2625
- strcpy (s , str_tolower_z (localized_full_days [tm -> tm_wday ], collid ));
2700
+ {
2701
+ char * str = str_tolower_z (localized_full_days [tm -> tm_wday ], collid );
2702
+
2703
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2704
+ strcpy (s , str );
2705
+ else
2706
+ ereport (ERROR ,
2707
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2708
+ errmsg ("localized string format value too long" )));
2709
+ }
2626
2710
else
2627
2711
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2628
2712
asc_tolower_z (days [tm -> tm_wday ]));
@@ -2631,23 +2715,50 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2631
2715
case DCH_DY :
2632
2716
INVALID_FOR_INTERVAL ;
2633
2717
if (S_TM (n -> suffix ))
2634
- strcpy (s , str_toupper_z (localized_abbrev_days [tm -> tm_wday ], collid ));
2718
+ {
2719
+ char * str = str_toupper_z (localized_abbrev_days [tm -> tm_wday ], collid );
2720
+
2721
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2722
+ strcpy (s , str );
2723
+ else
2724
+ ereport (ERROR ,
2725
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2726
+ errmsg ("localized string format value too long" )));
2727
+ }
2635
2728
else
2636
2729
strcpy (s , asc_toupper_z (days_short [tm -> tm_wday ]));
2637
2730
s += strlen (s );
2638
2731
break ;
2639
2732
case DCH_Dy :
2640
2733
INVALID_FOR_INTERVAL ;
2641
2734
if (S_TM (n -> suffix ))
2642
- strcpy (s , str_initcap_z (localized_abbrev_days [tm -> tm_wday ], collid ));
2735
+ {
2736
+ char * str = str_initcap_z (localized_abbrev_days [tm -> tm_wday ], collid );
2737
+
2738
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2739
+ strcpy (s , str );
2740
+ else
2741
+ ereport (ERROR ,
2742
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2743
+ errmsg ("localized string format value too long" )));
2744
+ }
2643
2745
else
2644
2746
strcpy (s , days_short [tm -> tm_wday ]);
2645
2747
s += strlen (s );
2646
2748
break ;
2647
2749
case DCH_dy :
2648
2750
INVALID_FOR_INTERVAL ;
2649
2751
if (S_TM (n -> suffix ))
2650
- strcpy (s , str_tolower_z (localized_abbrev_days [tm -> tm_wday ], collid ));
2752
+ {
2753
+ char * str = str_tolower_z (localized_abbrev_days [tm -> tm_wday ], collid );
2754
+
2755
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2756
+ strcpy (s , str );
2757
+ else
2758
+ ereport (ERROR ,
2759
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2760
+ errmsg ("localized string format value too long" )));
2761
+ }
2651
2762
else
2652
2763
strcpy (s , asc_tolower_z (days_short [tm -> tm_wday ]));
2653
2764
s += strlen (s );
0 commit comments