Fix several datatype input functions that were allowing unused bytes in their
authorTom Lane <[email protected]>
Fri, 11 Apr 2008 22:53:16 +0000 (22:53 +0000)
committerTom Lane <[email protected]>
Fri, 11 Apr 2008 22:53:16 +0000 (22:53 +0000)
results to contain uninitialized, unpredictable values.  While this was okay
as far as the datatypes themselves were concerned, it's a problem for the
parser because occurrences of the "same" literal might not be recognized as
equal by datumIsEqual (and hence not by equal()).  It seems sufficient to fix
this in the input functions since the only critical use of equal() is in the
parser's comparisons of ORDER BY and DISTINCT expressions.
Per a trouble report from Marc Cousin.

Patch all the way back.  Interestingly, array_in did not have the bug before
8.2, which may explain why the issue went unnoticed for so long.

contrib/ltree/ltree_io.c
src/backend/utils/adt/geo_ops.c

index ccc6fc8ff71576f6e9382afb8be6fad014ebf201..8ef4ecf3f84994849727cc195bdcb657b0fe1163 100644 (file)
@@ -117,7 +117,7 @@ ltree_in(PG_FUNCTION_ARGS)
                                 errmsg("syntax error"),
                                 errdetail("Unexpected end of line.")));
 
-       result = (ltree *) palloc(LTREE_HDRSIZE + totallen);
+       result = (ltree *) palloc0(LTREE_HDRSIZE + totallen);
        result->len = LTREE_HDRSIZE + totallen;
        result->numlevel = lptr - list;
        curlevel = LTREE_FIRST(result);
@@ -207,8 +207,7 @@ lquery_in(PG_FUNCTION_ARGS)
        }
 
        num++;
-       curqlevel = tmpql = (lquery_level *) palloc(ITEMSIZE * num);
-       memset((void *) tmpql, 0, ITEMSIZE * num);
+       curqlevel = tmpql = (lquery_level *) palloc0(ITEMSIZE * num);
        ptr = buf;
        while (*ptr)
        {
@@ -447,7 +446,7 @@ lquery_in(PG_FUNCTION_ARGS)
                curqlevel = NEXTLEV(curqlevel);
        }
 
-       result = (lquery *) palloc(totallen);
+       result = (lquery *) palloc0(totallen);
        result->len = totallen;
        result->numlevel = num;
        result->firstgood = 0;
index c2626404dcf946302a702bec1d126c87ccd7d238..6e7b995fbf5d1813511ab7c2b370a4c971a45311 100644 (file)
@@ -1425,6 +1425,8 @@ path_in(PG_FUNCTION_ARGS)
                                 errmsg("invalid input syntax for type path: \"%s\"", str)));
 
        path->closed = (!isopen);
+       /* prevent instability in unused pad bytes */
+       path->dummy = 0;
 
        PG_RETURN_PATH_P(path);
 }