]> granicus.if.org Git - postgresql/commitdiff
Avoid potential buffer overflow crash
authorPeter Eisentraut <peter_e@gmx.net>
Sat, 23 Nov 2013 12:25:37 +0000 (07:25 -0500)
committerPeter Eisentraut <peter_e@gmx.net>
Sat, 23 Nov 2013 12:31:07 +0000 (07:31 -0500)
A pointer to a C string was treated as a pointer to a "name" datum and
passed to SPI_execute_plan().  This pointer would then end up being
passed through datumCopy(), which would try to copy the entire 64 bytes
of name data, thus running past the end of the C string.  Fix by
converting the string to a proper name structure.

Found by LLVM AddressSanitizer.

src/backend/utils/adt/ruleutils.c

index ebfac92ee59bf41f9114e5b4494b36cc069566ab..bfebef89eb978dcf7c1fa540f91f5072a4fb7b6d 100644 (file)
@@ -454,7 +454,7 @@ pg_get_viewdef_worker(Oid viewoid, int prettyFlags)
         * Get the pg_rewrite tuple for the view's SELECT rule
         */
        args[0] = ObjectIdGetDatum(viewoid);
-       args[1] = PointerGetDatum(ViewSelectRuleName);
+       args[1] = DirectFunctionCall1(namein, CStringGetDatum(ViewSelectRuleName));
        nulls[0] = ' ';
        nulls[1] = ' ';
        spirc = SPI_execute_plan(plan_getviewrule, args, nulls, true, 2);