]> granicus.if.org Git - postgresql/commitdiff
pg_dump: Fix crash with invalid pg_cast row
authorPeter Eisentraut <peter_e@gmx.net>
Fri, 16 Mar 2012 17:55:41 +0000 (19:55 +0200)
committerPeter Eisentraut <peter_e@gmx.net>
Fri, 16 Mar 2012 18:34:59 +0000 (20:34 +0200)
An invalid combination of pg_cast.castfunc and pg_cast.castmethod
would result in a segmentation fault.  Now it prints a warning.

found by Coverity

src/bin/pg_dump/pg_dump.c

index 86d8a090624b24916df443275b763e936317313c..2b0a5ff81ad0be7984837d40792a2a1910b7ea41 100644 (file)
@@ -9477,18 +9477,21 @@ dumpCast(Archive *fout, CastInfo *cast)
                        appendPQExpBuffer(defqry, "WITH INOUT");
                        break;
                case COERCION_METHOD_FUNCTION:
-               {
-                       char   *fsig = format_function_signature(fout, funcInfo, true);
+                       if (funcInfo)
+                       {
+                               char   *fsig = format_function_signature(fout, funcInfo, true);
 
-                       /*
-                        * Always qualify the function name, in case it is not in
-                        * pg_catalog schema (format_function_signature won't qualify it).
-                        */
-                       appendPQExpBuffer(defqry, "WITH FUNCTION %s.%s",
-                                                         fmtId(funcInfo->dobj.namespace->dobj.name), fsig);
-                       free(fsig);
+                               /*
+                                * Always qualify the function name, in case it is not in
+                                * pg_catalog schema (format_function_signature won't qualify it).
+                                */
+                               appendPQExpBuffer(defqry, "WITH FUNCTION %s.%s",
+                                                                 fmtId(funcInfo->dobj.namespace->dobj.name), fsig);
+                               free(fsig);
+                       }
+                       else
+                               write_msg(NULL, "WARNING: bogus value in pg_cast.castfunc or pg_cast.castmethod field\n");
                        break;
-               }
                default:
                        write_msg(NULL, "WARNING: bogus value in pg_cast.castmethod field\n");
        }