$OpenBSD: patch-src_rrd_create_c,v 1.1 2017/12/05 16:50:10 sthen Exp $

Based on:

From f1edd121add94fe69ac22d991748d289b5eb76ae Mon Sep 17 00:00:00 2001
From: Tobias Oetiker <tobi@oetiker.ch>
Date: Sun, 11 Jun 2017 17:19:05 +0200
Subject: [PATCH] Remove all occurances of umask ... this is NOT thread safe!
 Fix for #794.

Index: src/rrd_create.c
--- src/rrd_create.c.orig
+++ src/rrd_create.c
@@ -1316,7 +1316,6 @@ done:
 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
@@ -1341,10 +1340,9 @@ int write_rrd(const char *outfilename, rrd_t *out) {
 	strcpy(tmpfilename, outfilename);
 	strcat(tmpfilename, "XXXXXX");
 	
-	/* fix CWE-377 */
-	saved_umask = umask(S_IRUSR|S_IWUSR);
+	/* 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;
@@ -1377,13 +1375,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 */
+		stat_buf.st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
 #endif                
 	    }
 	    if (chmod(tmpfilename, stat_buf.st_mode) != 0) {
