8000 Fix saving and restoring umask · etolbakov/postgres@a1f30ec · GitHub
  • [go: up one dir, main page]

    Skip to content

    Commit a1f30ec

    Browse files
    committed
    Fix saving and restoring umask
    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.
    1 parent e25f440 commit a1f30ec

    File tree

    2 files changed

    +21
    -3
    lines changed

    2 files changed

    +21
    -3
    lines changed

    src/backend/commands/copy.c

    Lines changed: 10 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -1802,7 +1802,16 @@ BeginCopyTo(Relation rel,
    18021802
    errmsg("relative path not allowed for COPY to file")));
    18031803

    18041804
    oumask = umask(S_IWGRP | S_IWOTH);
    1805-
    cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W);
    1805+
    PG_TRY();
    1806+
    {
    1807+
    cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W);
    1808+
    }
    1809+
    PG_CATCH();
    1810+
    {
    1811+
    umask(oumask);
    1812+
    PG_RE_THROW();
    1813+
    }
    1814+
    PG_END_TRY();
    18061815
    umask(oumask);
    18071816
    if (cstate->copy_file == NULL)
    18081817
    ereport(ERROR,

    src/backend/libpq/be-fsstubs.c

    Lines changed: 11 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -538,8 +538,17 @@ lo_export(PG_FUNCTION_ARGS)
    538538
    */
    539539
    text_to_cstring_buffer(filename, fnamebuf, sizeof(fnamebuf));
    540540
    oumask = umask(S_IWGRP | S_IWOTH);
    541-
    fd = OpenTransientFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY,
    542-
    S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
    541+
    PG_TRY();
    542+
    {
    543+
    fd = OpenTransientFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY,
    544+
    S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
    545+
    }
    546+
    PG_CATCH();
    547+
    {
    548+
    umask(oumask);
    549+
    PG_RE_THROW();
    550+
    }
    551+
    PG_END_TRY();
    543552
    umask(oumask);
    544553
    if (fd < 0)
    545554
    ereport(ERROR,

    0 commit comments

    Comments
     (0)
    0