Skip to content

Commit 0a9118c

Browse files
committed
ecpg: Fix error handling on OOMs when parsing timestamps
pgtypes_alloc() can return NULL when failing an allocation, which is something that PGTYPEStimestamp_defmt_asc() has forgotten about when translating a timestamp for 'D', 'r', 'R' and 'T' as these require a temporary allocation. This is unlikely going to be a problem in practice, so no backpatch is done. Author: Oleg Tselebrovskiy Discussion: https://postgr.es/m/bf47888585149f83b276861a1662f7e4@postgrespro.ru
1 parent a6c2188 commit 0a9118c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/interfaces/ecpg/pgtypeslib/dt_common.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,6 +2659,8 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp * d,
26592659
*/
26602660
pfmt++;
26612661
tmp = pgtypes_alloc(strlen("%m/%d/%y") + strlen(pstr) + 1);
2662+
if (!tmp)
2663+
return 1;
26622664
strcpy(tmp, "%m/%d/%y");
26632665
strcat(tmp, pfmt);
26642666
err = PGTYPEStimestamp_defmt_scan(&pstr, tmp, d, year, month, day, hour, minute, second, tz);
@@ -2784,6 +2786,8 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp * d,
27842786
case 'r':
27852787
pfmt++;
27862788
tmp = pgtypes_alloc(strlen("%I:%M:%S %p") + strlen(pstr) + 1);
2789+
if (!tmp)
2790+
return 1;
27872791
strcpy(tmp, "%I:%M:%S %p");
27882792
strcat(tmp, pfmt);
27892793
err = PGTYPEStimestamp_defmt_scan(&pstr, tmp, d, year, month, day, hour, minute, second, tz);
@@ -2792,6 +2796,8 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp * d,
27922796
case 'R':
27932797
pfmt++;
27942798
tmp = pgtypes_alloc(strlen("%H:%M") + strlen(pstr) + 1);
2799+
if (!tmp)
2800+
return 1;
27952801
strcpy(tmp, "%H:%M");
27962802
strcat(tmp, pfmt);
27972803
err = PGTYPEStimestamp_defmt_scan(&pstr, tmp, d, year, month, day, hour, minute, second, tz);
@@ -2837,6 +2843,8 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp * d,
28372843
case 'T':
28382844
pfmt++;
28392845
tmp = pgtypes_alloc(strlen("%H:%M:%S") + strlen(pstr) + 1);
2846+
if (!tmp)
2847+
return 1;
28402848
strcpy(tmp, "%H:%M:%S");
28412849
strcat(tmp, pfmt);
28422850
err = PGTYPEStimestamp_defmt_scan(&pstr, tmp, d, year, month, day, hour, minute, second, tz);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy