Blame SOURCES/unbound-1.7.3-symlink-traversal.patch

d9cda3
diff --git a/unbound-1.7.3/daemon/unbound.c b/unbound-1.7.3/daemon/unbound.c
d9cda3
index 1383110..66ed61d 100644
d9cda3
--- a/daemon/unbound.c
d9cda3
+++ b/daemon/unbound.c
d9cda3
@@ -327,18 +327,32 @@ readpid (const char* file)
d9cda3
 static void
d9cda3
 writepid (const char* pidfile, pid_t pid)
d9cda3
 {
d9cda3
-	FILE* f;
d9cda3
+	int fd;
d9cda3
+	char pidbuf[32];
d9cda3
+	size_t count = 0;
d9cda3
+	snprintf(pidbuf, sizeof(pidbuf), "%lu\n", (unsigned long)pid);
d9cda3
 
d9cda3
-	if ((f = fopen(pidfile, "w")) ==  NULL ) {
d9cda3
+    if((fd = open(pidfile, O_WRONLY | O_CREAT | O_TRUNC
d9cda3
+#ifdef O_NOFOLLOW
d9cda3
+		| O_NOFOLLOW
d9cda3
+#endif
d9cda3
+		, 0644)) == -1) {
d9cda3
 		log_err("cannot open pidfile %s: %s", 
d9cda3
 			pidfile, strerror(errno));
d9cda3
 		return;
d9cda3
 	}
d9cda3
-	if(fprintf(f, "%lu\n", (unsigned long)pid) < 0) {
d9cda3
-		log_err("cannot write to pidfile %s: %s", 
d9cda3
-			pidfile, strerror(errno));
d9cda3
+    while(count < strlen(pidbuf)) {
d9cda3
+		ssize_t r = write(fd, pidbuf+count, strlen(pidbuf)-count);
d9cda3
+		if(r == -1) {
d9cda3
+			if(errno == EAGAIN || errno == EINTR)
d9cda3
+				continue;
d9cda3
+			log_err("cannot write to pidfile %s: %s",
d9cda3
+				pidfile, strerror(errno));
d9cda3
+			break;
d9cda3
+		}
d9cda3
+		count += r;
d9cda3
 	}
d9cda3
-	fclose(f);
d9cda3
+	close(fd);
d9cda3
 }
d9cda3
 
d9cda3
 /**