]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Remove all occurances of umask ... this is NOT thread safe! Fix for #794.
authorTobias Oetiker <tobi@oetiker.ch>
Sun, 11 Jun 2017 15:19:05 +0000 (17:19 +0200)
committerTobias Oetiker <tobi@oetiker.ch>
Sun, 11 Jun 2017 15:19:05 +0000 (17:19 +0200)
doc/rrdcreate.pod
src/rrd_create.c

index f2e545d436deb1f95372bb085794f438cc874f74..cb84c53d524cce20498e11409571e01ecb8e098a 100644 (file)
@@ -743,6 +743,12 @@ divides each PDP of the AccumDuration by the corresponding PDP of
 TotalRequests and stores the average request duration. The remainder of the
 RPN expression handles the divide by zero case.
 
+=head1 SECURITY
+
+Note that new rrd files will have the permission 0622 regarless of your
+umask setting. If a file with the same name previously exists, its
+permission settings will be copied to the new file.
+
 =head1 AUTHORS
 
 Tobias Oetiker E<lt>tobi@oetiker.chE<gt>, Peter Stamfest E<lt>peter@stamfest.atE<gt>
index 536b1f10e12774e371c9d5c7046269c26b842a2b..7be6bcf74fdba461aef50e971c81af258a7cc2ab 100644 (file)
@@ -4,6 +4,7 @@
  * rrd_create.c  creates new rrds
  *****************************************************************************/
 
+#include "mutex.h"
 #include <stdlib.h>
 #include <time.h>
 #include <locale.h>
@@ -1315,10 +1316,10 @@ done:
     return rc;
 }
 
+
 int write_rrd(const char *outfilename, rrd_t *out) {
     int rc = -1;
     char *tmpfilename = NULL;
-    mode_t saved_umask;
 
     /* write out the new file */
 #ifdef HAVE_LIBRADOS
@@ -1343,10 +1344,10 @@ int write_rrd(const char *outfilename, rrd_t *out) {
        strcpy(tmpfilename, outfilename);
        strcat(tmpfilename, "XXXXXX");
        
-       /* fix CWE-377 */
-       saved_umask = umask(S_IWGRP|S_IWOTH);
+        /* this is 0600 according to the manual page */        
        int tmpfd = mkstemp(tmpfilename);
-       umask(saved_umask);
+
+       
        if (tmpfd < 0) {
            rrd_set_error("Cannot create temporary file");
            goto done;
@@ -1379,13 +1380,8 @@ int write_rrd(const char *outfilename, rrd_t *out) {
                 stat_buf.st_mode = _S_IREAD | _S_IWRITE;  // have to test it is 
 #else
                /* an error occurred (file not found, maybe?). Anyway:
-                  set the mode to 0666 using current umask */
-               stat_buf.st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
-               
-               mode_t mask = umask(0);
-               umask(mask);
-
-               stat_buf.st_mode &= ~mask;
+                  set the mode to 0644 using current umask */
+               stat_buf.st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
 #endif                
            }
            if (chmod(tmpfilename, stat_buf.st_mode) != 0) {