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
/* ----------
@@ -525,10 +525,12 @@ do { \
525
525
* Suffixes definition for DATE-TIME TO/FROM CHAR
526
526
* ----------
527
527
*/
528
+ #define TM_SUFFIX_LEN 2
529
+
528
530
static KeySuffix DCH_suff [] = {
529
531
{"FM" , 2 , DCH_S_FM , SUFFTYPE_PREFIX },
530
532
{"fm" , 2 , DCH_S_FM , SUFFTYPE_PREFIX },
531
- {"TM" , 2 , DCH_S_TM , SUFFTYPE_PREFIX },
533
+ {"TM" , TM_SUFFIX_LEN , DCH_S_TM , SUFFTYPE_PREFIX },
532
534
{"tm" , 2 , DCH_S_TM , SUFFTYPE_PREFIX },
533
535
{"TH" , 2 , DCH_S_TH , SUFFTYPE_POSTFIX },
534
536
{"th" , 2 , DCH_S_th , SUFFTYPE_POSTFIX },
@@ -537,6 +539,7 @@ static KeySuffix DCH_suff[] = {
537
539
{NULL , 0 , 0 , 0 }
538
540
};
539
541
542
+
540
543
/* ----------
541
544
* Format-pictures (KeyWord).
542
545
*
@@ -2532,7 +2535,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2532
2535
if (!tm -> tm_mon )
2533
2536
break ;
2534
2537
if (S_TM (n -> suffix ))
2535
- strcpy (s , str_toupper_z (localized_full_months [tm -> tm_mon - 1 ], collid ));
2538
+ {
2539
+ char * str = str_toupper_z (localized_full_months [tm -> tm_mon - 1 ], collid );
2540
+
2541
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2542
+ strcpy (s , str );
2543
+ else
2544
+ ereport (ERROR ,
2545
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2546
+ errmsg ("localized string format value too long" )));
2547
+ }
2536
2548
else
2537
2549
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2538
2550
asc_toupper_z (months_full [tm -> tm_mon - 1 ]));
@@ -2543,7 +2555,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2543
2555
if (!tm -> tm_mon )
2544
2556
break ;
2545
2557
if (S_TM (n -> suffix ))
2546
- strcpy (s , str_initcap_z (localized_full_months [tm -> tm_mon - 1 ], collid ));
2558
+ {
2559
+ char * str = str_initcap_z (localized_full_months [tm -> tm_mon - 1 ], collid );
2560
+
2561
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2562
+ strcpy (s , str );
2563
+ else
2564
+ ereport (ERROR ,
2565
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2566
+ errmsg ("localized string format value too long" )));
2567
+ }
2547
2568
else
2548
2569
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2549
2570
months_full [tm -> tm_mon - 1 ]);
@@ -2554,7 +2575,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2554
2575
if (!tm -> tm_mon )
2555
2576
break ;
2556
2577
if (S_TM (n -> suffix ))
2557
- strcpy (s , str_tolower_z (localized_full_months [tm -> tm_mon - 1 ], collid ));
2578
+ {
2579
+ char * str = str_tolower_z (localized_full_months [tm -> tm_mon - 1 ], collid );
2580
+
2581
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2582
+ strcpy (s , str );
2583
+ else
2584
+ ereport (ERROR ,
2585
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2586
+ errmsg ("localized string format value too long" )));
2587
+ }
2558
2588
else
2559
2589
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2560
2590
asc_tolower_z (months_full [tm -> tm_mon - 1 ]));
@@ -2565,7 +2595,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2565
2595
if (!tm -> tm_mon )
2566
2596
break ;
2567
2597
if (S_TM (n -> suffix ))
2568
- strcpy (s , str_toupper_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid ));
2598
+ {
2599
+ char * str = str_toupper_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid );
2600
+
2601
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2602
+ strcpy (s , str );
2603
+ else
2604
+ ereport (ERROR ,
2605
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2606
+ errmsg ("localized string format value too long" )));
2607
+ }
2569
2608
else
2570
2609
strcpy (s , asc_toupper_z (months [tm -> tm_mon - 1 ]));
2571
2610
s += strlen (s );
@@ -2575,7 +2614,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2575
2614
if (!tm -> tm_mon )
2576
2615
break ;
2577
2616
if (S_TM (n -> suffix ))
2578
- strcpy (s , str_initcap_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid ));
2617
+ {
2618
+ char * str = str_initcap_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid );
2619
+
2620
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2621
+ strcpy (s , str );
2622
+ else
2623
+ ereport (ERROR ,
2624
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2625
+ errmsg ("localized string format value too long" )));
2626
+ }
2579
2627
else
2580
2628
strcpy (s , months [tm -> tm_mon - 1 ]);
2581
2629
s += strlen (s );
@@ -2585,7 +2633,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2585
2633
if (!tm -> tm_mon )
2586
2634
break ;
2587
2635
if (S_TM (n -> suffix ))
2588
- strcpy (s , str_tolower_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid ));
2636
+ {
2637
+ char * str = str_tolower_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid );
2638
+
2639
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2640
+ strcpy (s , str );
2641
+ else
2642
+ ereport (ERROR ,
2643
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2644
+ errmsg ("localized string format value too long" )));
2645
+ }
2589
2646
else
2590
2647
strcpy (s , asc_tolower_z (months [tm -> tm_mon - 1 ]));
2591
2648
s += strlen (s );
@@ -2599,7 +2656,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2599
2656
case DCH_DAY :
2600
2657
INVALID_FOR_INTERVAL ;
2601
2658
if (S_TM (n -> suffix ))
2602
- strcpy (s , str_toupper_z (localized_full_days [tm -> tm_wday ], collid ));
2659
+ {
2660
+ char * str = str_toupper_z (localized_full_days [tm -> tm_wday ], collid );
2661
+
2662
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2663
+ strcpy (s , str );
2664
+ else
2665
+ ereport (ERROR ,
2666
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2667
+ errmsg ("localized string format value too long" )));
2668
+ }
2603
2669
else
2604
2670
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2605
2671
asc_toupper_z (days [tm -> tm_wday ]));
@@ -2608,7 +2674,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2608
2674
case DCH_Day :
2609
2675
INVALID_FOR_INTERVAL ;
2610
2676
if (S_TM (n -> suffix ))
2611
- strcpy (s , str_initcap_z (localized_full_days [tm -> tm_wday ], collid ));
2677
+ {
2678
+ char * str = str_initcap_z (localized_full_days [tm -> tm_wday ], collid );
2679
+
2680
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2681
+ strcpy (s , str );
2682
+ else
2683
+ ereport (ERROR ,
2684
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2685
+ errmsg ("localized string format value too long" )));
2686
+ }
2612
2687
else
2613
2688
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2614
2689
days [tm -> tm_wday ]);
@@ -2617,7 +2692,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2617
2692
case DCH_day :
2618
2693
INVALID_FOR_INTERVAL ;
2619
2694
if (S_TM (n -> suffix ))
2620
- strcpy (s , str_tolower_z (localized_full_days [tm -> tm_wday ], collid ));
2695
+ {
2696
+ char * str = str_tolower_z (localized_full_days [tm -> tm_wday ], collid );
2697
+
2698
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2699
+ strcpy (s , str );
2700
+ else
2701
+ ereport (ERROR ,
2702
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2703
+ errmsg ("localized string format value too long" )));
2704
+ }
2621
2705
else
2622
2706
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2623
2707
asc_tolower_z (days [tm -> tm_wday ]));
@@ -2626,23 +2710,50 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2626
2710
case DCH_DY :
2627
2711
INVALID_FOR_INTERVAL ;
2628
2712
if (S_TM (n -> suffix ))
2629
- strcpy (s , str_toupper_z (localized_abbrev_days [tm -> tm_wday ], collid ));
2713
+ {
2714
+ char * str = str_toupper_z (localized_abbrev_days [tm -> tm_wday ], collid );
2715
+
2716
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2717
+ strcpy (s , str );
2718
+ else
2719
+ ereport (ERROR ,
2720
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2721
+ errmsg ("localized string format value too long" )));
2722
+ }
2630
2723
else
2631
2724
strcpy (s , asc_toupper_z (days_short [tm -> tm_wday ]));
2632
2725
s += strlen (s );
2633
2726
break ;
2634
2727
case DCH_Dy :
2635
2728
INVALID_FOR_INTERVAL ;
2636
2729
if (S_TM (n -> suffix ))
2637
- strcpy (s , str_initcap_z (localized_abbrev_days [tm -> tm_wday ], collid ));
2730
+ {
2731
+ char * str = str_initcap_z (localized_abbrev_days [tm -> tm_wday ], collid );
2732
+
2733
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2734
+ strcpy (s , str );
2735
+ else
2736
+ ereport (ERROR ,
2737
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2738
+ errmsg ("localized string format value too long" )));
2739
+ }
2638
2740
else
2639
2741
strcpy (s , days_short [tm -> tm_wday ]);
2640
2742
s += strlen (s );
2641
2743
break ;
2642
2744
case DCH_dy :
2643
2745
INVALID_FOR_INTERVAL ;
2644
2746
if (S_TM (n -> suffix ))
2645
- strcpy (s , str_tolower_z (localized_abbrev_days [tm -> tm_wday ], collid ));
2747
+ {
2748
+ char * str = str_tolower_z (localized_abbrev_days [tm -> tm_wday ], collid );
2749
+
2750
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2751
+ strcpy (s , str );
2752
+ else
2753
+ ereport (ERROR ,
2754
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2755
+ errmsg ("localized string format value too long" )));
2756
+ }
2646
2757
else
2647
2758
strcpy (s , asc_tolower_z (days_short [tm -> tm_wday ]));
2648
2759
s += strlen (s );
0 commit comments