]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix for #303 CVE-2020-28935 : Fix that symlink does not interfere
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Mon, 23 Nov 2020 12:42:11 +0000 (13:42 +0100)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Mon, 23 Nov 2020 12:42:11 +0000 (13:42 +0100)
  with chown of pidfile.

daemon/unbound.c
doc/Changelog

index cd0fd69f2ca48e582a0b6491c2b90de5dcdcc48f..45537d5c9ed99ee1c98bbb2fa09ffa9f85d959a8 100644 (file)
@@ -341,18 +341,32 @@ readpid (const char* file)
 static void
 writepid (const char* pidfile, pid_t pid)
 {
-       FILE* f;
+       int fd;
+       char pidbuf[32];
+       size_t count = 0;
+       snprintf(pidbuf, sizeof(pidbuf), "%lu\n", (unsigned long)pid);
 
-       if ((f = fopen(pidfile, "w")) ==  NULL ) {
+       if((fd = open(pidfile, O_WRONLY | O_CREAT | O_TRUNC
+#ifdef O_NOFOLLOW
+               | O_NOFOLLOW
+#endif
+               , 0644)) == -1) {
                log_err("cannot open pidfile %s: %s", 
                        pidfile, strerror(errno));
                return;
        }
-       if(fprintf(f, "%lu\n", (unsigned long)pid) < 0) {
-               log_err("cannot write to pidfile %s: %s", 
-                       pidfile, strerror(errno));
+       while(count < strlen(pidbuf)) {
+               ssize_t r = write(fd, pidbuf+count, strlen(pidbuf)-count);
+               if(r == -1) {
+                       if(errno == EAGAIN || errno == EINTR)
+                               continue;
+                       log_err("cannot write to pidfile %s: %s",
+                               pidfile, strerror(errno));
+                       break;
+               }
+               count += r;
        }
-       fclose(f);
+       close(fd);
 }
 
 /**
index cfaa3d0984caec490d6e6a9ea5fd955206487364..5bb0f05f30cda0255a1f6324d280e2ac8fa6d087 100644 (file)
@@ -6,6 +6,8 @@
          supported by protocol.
        - Fix #347: IP_DONTFRAG broken on Apple xcode 12.2.
        - Option to toggle udp-connect, default is enabled.
+       - Fix for #303 CVE-2020-28935 : Fix that symlink does not interfere
+         with chown of pidfile.
 
 12 November 2020: Wouter
        - Fix to connect() to UDP destinations, default turned on,