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