OSDN Git Service

Set the permission of a temporary file that pgs2textporter1() uses to 0600.
authorMasaoFujii <masao.fujii@gmail.com>
Fri, 17 Jul 2015 09:33:43 +0000 (18:33 +0900)
committerMasaoFujii <masao.fujii@gmail.com>
Fri, 17 Jul 2015 09:33:43 +0000 (18:33 +0900)
This change ensures that only the owner of PostgreSQL server can read and
write such temporary file.

Sawada Masahiko

ludia_funcs.c

index 2c36ba6..4c278dd 100644 (file)
@@ -75,6 +75,7 @@ static bool                   EscapeSnippetKeyword(char **s, size_t *slen);
 
 #ifdef TEXTPORTER
 #define TEXTPORTER_TMPDIR                      "/tmp"
+#define TEXTPORTER_MKSTEMP_UMASK               0177
 #define TEXTPORTER_GROUPNAME           "UTF-8"
 #define TEXTPORTER_DEFLANGNAME         "Japanese"
 #define TEXTPORTER_BBIGENDIAN          1
@@ -84,6 +85,7 @@ static bool                   EscapeSnippetKeyword(char **s, size_t *slen);
 #define TEXTPORTER_SIZE                                0
 #define TEXTPORTER_CSV_C                       0
 
+
 /* GUC variables for pgs2textpoter1 */
 static int     textporter_error = ERROR;
 static unsigned int    textporter_option = TEXTPORTER_OPTION;
@@ -239,6 +241,7 @@ pgs2textporter1(PG_FUNCTION_ARGS)
        text    *result = NULL;
        struct stat     statbuf;
        bool    return_null = false;
+       mode_t  oumask;
 
        /* Confirm that database encoding is UTF-8 */
        GetSennaEncoding();
@@ -248,8 +251,13 @@ pgs2textporter1(PG_FUNCTION_ARGS)
                /*
                 * Generate a unique temporary filename where text data gotten
                 * from application file by TextPorter is stored temporarily.
+                * Set the permission of a temporary file to 0600 to ensure that
+                * only the owner of PostgreSQL server can read and write the file.
                 */
+               oumask = umask(TEXTPORTER_MKSTEMP_UMASK);
                tmpfd = mkstemp(txtfile);
+               umask(oumask);
+
                if (tmpfd < 0)
                        ereport(ERROR,
                                        (errcode_for_file_access(),