repeat() fix:
authorBruce Momjian
Thu, 22 Aug 2002 04:54:20 +0000 (04:54 +0000)
committerBruce Momjian
Thu, 22 Aug 2002 04:54:20 +0000 (04:54 +0000)
> Neil Conway  writes:
> > +   /* Check for integer overflow */
> > +   if (tlen / slen != count)
> > +           elog(ERROR, "Requested buffer is too large.");
>
> What about slen == 0?

Good point -- that wouldn't cause incorrect results or a security
problem, but it would reject input that we should really accept.

Revised patch is attached.

Neil Conway

src/backend/utils/adt/oracle_compat.c

index 7634e0cdaf93cad6a064a8a3416e850f81a54cb7..dfeb18c551bff90cdf14c76639d06c7b91512b78 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.38 2002/06/20 20:51:45 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.39 2002/08/22 04:54:20 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -997,6 +997,10 @@ repeat(PG_FUNCTION_ARGS)
    slen = (VARSIZE(string) - VARHDRSZ);
    tlen = (VARHDRSZ + (count * slen));
 
+   /* Check for integer overflow */
+   if (slen != 0 && count != 0 && tlen / slen != count)
+       elog(ERROR, "Requested buffer is too large.");
+
    result = (text *) palloc(tlen);
 
    VARATT_SIZEP(result) = tlen;