Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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>
Sat, 23 Sep 2017 14:03:36 +0000 (10:03 -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 41a828c2fe44788a10138f8e11e562b73816c56b..feab7aa6e2a8ab84b9b37bacedacc4e4556a808a 100644 (file)
@@ -1802,7 +1802,16 @@ BeginCopyTo(Relation rel,
                      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)
                ereport(ERROR,
index 50e416da79ebc77d934929992ce26873f572aa2d..0112428e7d0c42e00b7eae2b4335fdc618f8628c 100644 (file)
@@ -538,8 +538,17 @@ 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,