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