aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2014-10-06 21:23:20 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2014-10-06 21:23:35 -0400
commitd3cfe20c6dc498f9294d07c7803a8cc776f8db31 (patch)
tree74cb0d410014c63f876ffa11ea0ef70af8801b5a
parent3cd085ee251ba1499a3dd94cbea809fe4bdc55a5 (diff)
downloadpostgresql-d3cfe20c6dc498f9294d07c7803a8cc776f8db31.tar.gz
postgresql-d3cfe20c6dc498f9294d07c7803a8cc776f8db31.zip
Fix array overrun in ecpg's version of ParseDateTime().
The code wrote a value into the caller's field[] array before checking to see if there was room, which of course is backwards. Per report from Michael Paquier. I fixed the equivalent bug in the backend's version of this code way back in 630684d3a130bb93, but failed to think about ecpg's copy. Fortunately this doesn't look like it would be exploitable for anything worse than a core dump: an external attacker would have no control over the single word that gets written.
-rw-r--r--src/interfaces/ecpg/pgtypeslib/dt_common.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/interfaces/ecpg/pgtypeslib/dt_common.c b/src/interfaces/ecpg/pgtypeslib/dt_common.c
index 18178dd34b8..5e0e8b39d07 100644
--- a/src/interfaces/ecpg/pgtypeslib/dt_common.c
+++ b/src/interfaces/ecpg/pgtypeslib/dt_common.c
@@ -1682,6 +1682,7 @@ DecodePosixTimezone(char *str, int *tzp)
*
* The "lowstr" work buffer must have at least strlen(timestr) + MAXDATEFIELDS
* bytes of space. On output, field[] entries will point into it.
+ * The field[] and ftype[] arrays must have at least MAXDATEFIELDS entries.
*/
int
ParseDateTime(char *timestr, char *lowstr,
@@ -1695,9 +1696,9 @@ ParseDateTime(char *timestr, char *lowstr,
while (*(*endstr) != '\0')
{
/* Record start of current field */
- field[nf] = lp;
if (nf >= MAXDATEFIELDS)
return -1;
+ field[nf] = lp;
/* leading digit? then date or time */
if (isdigit((unsigned char) *(*endstr)))