]> granicus.if.org Git - postgresql/commitdiff
Fix saving and restoring umask
authorPeter Eisentraut <peter_e@gmx.net>
Fri, 22 Sep 2017 20:50:59 +0000 (16:50 -0400)
committerPeter Eisentraut <peter_e@gmx.net>
Fri, 22 Sep 2017 21:10:36 +0000 (17:10 -0400)
In two cases, we set a different umask for some piece of code and
restore it afterwards.  But if the contained code errors out, the umask
is not restored.  So add TRY/CATCH blocks to fix that.

src/backend/commands/copy.c
src/backend/libpq/be-fsstubs.c

index c6fa44563c99ce2c101baed4db2e4aab32aa0e8b..7c004ffad8a6bfadfffe34da7a155cd6acccdde1 100644 (file)
@@ -1826,7 +1826,16 @@ BeginCopyTo(ParseState *pstate,
                                                 errmsg("relative path not allowed for COPY to file")));
 
                        oumask = umask(S_IWGRP | S_IWOTH);
-                       cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W);
+                       PG_TRY();
+                       {
+                               cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W);
+                       }
+                       PG_CATCH();
+                       {
+                               umask(oumask);
+                               PG_RE_THROW();
+                       }
+                       PG_END_TRY();
                        umask(oumask);
                        if (cstate->copy_file == NULL)
                        {
index bf45461b2f15453ea58923e250f60eb1be73bf3f..19b34bfc84af0dc12f5ea7bf41db021e9c8a50ee 100644 (file)
@@ -538,8 +538,17 @@ be_lo_export(PG_FUNCTION_ARGS)
         */
        text_to_cstring_buffer(filename, fnamebuf, sizeof(fnamebuf));
        oumask = umask(S_IWGRP | S_IWOTH);
-       fd = OpenTransientFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY,
-                                                  S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+       PG_TRY();
+       {
+               fd = OpenTransientFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY,
+                                                          S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+       }
+       PG_CATCH();
+       {
+               umask(oumask);
+               PG_RE_THROW();
+       }
+       PG_END_TRY();
        umask(oumask);
        if (fd < 0)
                ereport(ERROR,