1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-30 06:01:21 +03:00

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
This commit is contained in:
Michael Paquier
2024-02-19 09:05:51 +09:00
parent a6c21887a9
commit 0a9118ccc0

View File

@@ -2659,6 +2659,8 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp * d,
*/ */
pfmt++; pfmt++;
tmp = pgtypes_alloc(strlen("%m/%d/%y") + strlen(pstr) + 1); tmp = pgtypes_alloc(strlen("%m/%d/%y") + strlen(pstr) + 1);
if (!tmp)
return 1;
strcpy(tmp, "%m/%d/%y"); strcpy(tmp, "%m/%d/%y");
strcat(tmp, pfmt); strcat(tmp, pfmt);
err = PGTYPEStimestamp_defmt_scan(&pstr, tmp, d, year, month, day, hour, minute, second, tz); 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,
case 'r': case 'r':
pfmt++; pfmt++;
tmp = pgtypes_alloc(strlen("%I:%M:%S %p") + strlen(pstr) + 1); tmp = pgtypes_alloc(strlen("%I:%M:%S %p") + strlen(pstr) + 1);
if (!tmp)
return 1;
strcpy(tmp, "%I:%M:%S %p"); strcpy(tmp, "%I:%M:%S %p");
strcat(tmp, pfmt); strcat(tmp, pfmt);
err = PGTYPEStimestamp_defmt_scan(&pstr, tmp, d, year, month, day, hour, minute, second, tz); 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,
case 'R': case 'R':
pfmt++; pfmt++;
tmp = pgtypes_alloc(strlen("%H:%M") + strlen(pstr) + 1); tmp = pgtypes_alloc(strlen("%H:%M") + strlen(pstr) + 1);
if (!tmp)
return 1;
strcpy(tmp, "%H:%M"); strcpy(tmp, "%H:%M");
strcat(tmp, pfmt); strcat(tmp, pfmt);
err = PGTYPEStimestamp_defmt_scan(&pstr, tmp, d, year, month, day, hour, minute, second, tz); 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,
case 'T': case 'T':
pfmt++; pfmt++;
tmp = pgtypes_alloc(strlen("%H:%M:%S") + strlen(pstr) + 1); tmp = pgtypes_alloc(strlen("%H:%M:%S") + strlen(pstr) + 1);
if (!tmp)
return 1;
strcpy(tmp, "%H:%M:%S"); strcpy(tmp, "%H:%M:%S");
strcat(tmp, pfmt); strcat(tmp, pfmt);
err = PGTYPEStimestamp_defmt_scan(&pstr, tmp, d, year, month, day, hour, minute, second, tz); err = PGTYPEStimestamp_defmt_scan(&pstr, tmp, d, year, month, day, hour, minute, second, tz);