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
*
@@ -2534,7 +2537,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2534
2537
if (!tm -> tm_mon )
2535
2538
break ;
2536
2539
if (S_TM (n -> suffix ))
2537
- strcpy (s , str_toupper_z (localized_full_months [tm -> tm_mon - 1 ], collid ));
2540
+ {
2541
+ char * str = str_toupper_z (localized_full_months [tm -> tm_mon - 1 ], collid );
2542
+
2543
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2544
+ strcpy (s , str );
2545
+ else
2546
+ ereport (ERROR ,
2547
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2548
+ errmsg ("localized string format value too long" )));
2549
+ }
2538
2550
else
2539
2551
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2540
2552
asc_toupper_z (months_full [tm -> tm_mon - 1 ]));
@@ -2545,7 +2557,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2545
2557
if (!tm -> tm_mon )
2546
2558
break ;
2547
2559
if (S_TM (n -> suffix ))
2548
- strcpy (s , str_initcap_z (localized_full_months [tm -> tm_mon - 1 ], collid ));
2560
+ {
2561
+ char * str = str_initcap_z (localized_full_months [tm -> tm_mon - 1 ], collid );
2562
+
2563
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2564
+ strcpy (s , str );
2565
+ else
2566
+ ereport (ERROR ,
2567
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2568
+ errmsg ("localized string format value too long" )));
2569
+ }
2549
2570
else
2550
2571
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2551
2572
months_full [tm -> tm_mon - 1 ]);
@@ -2556,7 +2577,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2556
2577
if (!tm -> tm_mon )
2557
2578
break ;
2558
2579
if (S_TM (n -> suffix ))
2559
- strcpy (s , str_tolower_z (localized_full_months [tm -> tm_mon - 1 ], collid ));
2580
+ {
2581
+ char * str = str_tolower_z (localized_full_months [tm -> tm_mon - 1 ], collid );
2582
+
2583
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2584
+ strcpy (s , str );
2585
+ else
2586
+ ereport (ERROR ,
2587
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2588
+ errmsg ("localized string format value too long" )));
2589
+ }
2560
2590
else
2561
2591
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2562
2592
asc_tolower_z (months_full [tm -> tm_mon - 1 ]));
@@ -2567,7 +2597,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2567
2597
if (!tm -> tm_mon )
2568
2598
break ;
2569
2599
if (S_TM (n -> suffix ))
2570
- strcpy (s , str_toupper_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid ));
2600
+ {
2601
+ char * str = str_toupper_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid );
2602
+
2603
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2604
+ strcpy (s , str );
2605
+ else
2606
+ ereport (ERROR ,
2607
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2608
+ errmsg ("localized string format value too long" )));
2609
+ }
2571
2610
else
2572
2611
strcpy (s , asc_toupper_z (months [tm -> tm_mon - 1 ]));
2573
2612
s += strlen (s );
@@ -2577,7 +2616,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2577
2616
if (!tm -> tm_mon )
2578
2617
break ;
2579
2618
if (S_TM (n -> suffix ))
2580
- strcpy (s , str_initcap_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid ));
2619
+ {
2620
+ char * str = str_initcap_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid );
2621
+
2622
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2623
+ strcpy (s , str );
2624
+ else
2625
+ ereport (ERROR ,
2626
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2627
+ errmsg ("localized string format value too long" )));
2628
+ }
2581
2629
else
2582
2630
strcpy (s , months [tm -> tm_mon - 1 ]);
2583
2631
s += strlen (s );
@@ -2587,7 +2635,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2587
2635
if (!tm -> tm_mon )
2588
2636
break ;
2589
2637
if (S_TM (n -> suffix ))
2590
- strcpy (s , str_tolower_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid ));
2638
+ {
2639
+ char * str = str_tolower_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid );
2640
+
2641
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2642
+ strcpy (s , str );
2643
+ else
2644
+ ereport (ERROR ,
2645
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2646
+ errmsg ("localized string format value too long" )));
2647
+ }
2591
2648
else
2592
2649
strcpy (s , asc_tolower_z (months [tm -> tm_mon - 1 ]));
2593
2650
s += strlen (s );
@@ -2601,7 +2658,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2601
2658
case DCH_DAY :
2602
2659
INVALID_FOR_INTERVAL ;
2603
2660
if (S_TM (n -> suffix ))
2604
- strcpy (s , str_toupper_z (localized_full_days [tm -> tm_wday ], collid ));
2661
+ {
2662
+ char * str = str_toupper_z (localized_full_days [tm -> tm_wday ], collid );
2663
+
2664
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2665
+ strcpy (s , str );
2666
+ else
2667
+ ereport (ERROR ,
2668
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2669
+ errmsg ("localized string format value too long" )));
2670
+ }
2605
2671
else
2606
2672
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2607
2673
asc_toupper_z (days [tm -> tm_wday ]));
@@ -2610,7 +2676,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2610
2676
case DCH_Day :
2611
2677
INVALID_FOR_INTERVAL ;
2612
2678
if (S_TM (n -> suffix ))
2613
- strcpy (s , str_initcap_z (localized_full_days [tm -> tm_wday ], collid ));
2679
+ {
2680
+ char * str = str_initcap_z (localized_full_days [tm -> tm_wday ], collid );
2681
+
2682
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2683
+ strcpy (s , str );
2684
+ else
2685
+ ereport (ERROR ,
2686
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2687
+ errmsg ("localized string format value too long" )));
2688
+ }
2614
2689
else
2615
2690
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2616
2691
days [tm -> tm_wday ]);
@@ -2619,7 +2694,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2619
2694
case DCH_day :
2620
2695
INVALID_FOR_INTERVAL ;
2621
2696
if (S_TM (n -> suffix ))
2622
- strcpy (s , str_tolower_z (localized_full_days [tm -> tm_wday ], collid ));
2697
+ {
2698
+ char * str = str_tolower_z (localized_full_days [tm -> tm_wday ], collid );
2699
+
2700
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2701
+ strcpy (s , str );
2702
+ else
2703
+ ereport (ERROR ,
2704
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2705
+ errmsg ("localized string format value too long" )));
2706
+ }
2623
2707
else
2624
2708
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2625
2709
asc_tolower_z (days [tm -> tm_wday ]));
@@ -2628,23 +2712,50 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2628
2712
case DCH_DY :
2629
2713
INVALID_FOR_INTERVAL ;
2630
2714
if (S_TM (n -> suffix ))
2631
- strcpy (s , str_toupper_z (localized_abbrev_days [tm -> tm_wday ], collid ));
2715
+ {
2716
+ char * str = str_toupper_z (localized_abbrev_days [tm -> tm_wday ], collid );
2717
+
2718
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2719
+ strcpy (s , str );
2720
+ else
2721
+ ereport (ERROR ,
2722
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2723
+ errmsg ("localized string format value too long" )));
2724
+ }
2632
2725
else
2633
2726
strcpy (s , asc_toupper_z (days_short [tm -> tm_wday ]));
2634
2727
s += strlen (s );
2635
2728
break ;
2636
2729
case DCH_Dy :
2637
2730
INVALID_FOR_INTERVAL ;
2638
2731
if (S_TM (n -> suffix ))
2639
- strcpy (s , str_initcap_z (localized_abbrev_days [tm -> tm_wday ], collid ));
2732
+ {
2733
+ char * str = str_initcap_z (localized_abbrev_days [tm -> tm_wday ], collid );
2734
+
2735
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2736
+ strcpy (s , str );
2737
+ else
2738
+ ereport (ERROR ,
2739
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2740
+ errmsg ("localized string format value too long" )));
2741
+ }
2640
2742
else
2641
2743
strcpy (s , days_short [tm -> tm_wday ]);
2642
2744
s += strlen (s );
2643
2745
break ;
2644
2746
case DCH_dy :
2645
2747
INVALID_FOR_INTERVAL ;
2646
2748
if (S_TM (n -> suffix ))
2647
- strcpy (s , str_tolower_z (localized_abbrev_days [tm -> tm_wday ], collid ));
2749
+ {
2750
+ char * str = str_tolower_z (localized_abbrev_days [tm -> tm_wday ], collid );
2751
+
2752
+ if (strlen (str ) < (n -> key -> len + TM_SUFFIX_LEN ) * DCH_MAX_ITEM_SIZ )
2753
+ strcpy (s , str );
2754
+ else
2755
+ ereport (ERROR ,
2756
+ (errcode (ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ),
2757
+ errmsg ("localized string format value too long" )));
2758
+ }
2648
2759
else
2649
2760
strcpy (s , asc_tolower_z (days_short [tm -> tm_wday ]));
2650
2761
s += strlen (s );
0 commit comments