summaryrefslogtreecommitdiff
path: root/debian/patches/0006-guard-write.patch
blob: b2cab9025d0d027e82fd16e04ab804ba8051946c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
From: "Barak A. Pearlmutter" <barak+git@cs.nuim.ie>
Date: Wed, 18 Apr 2012 11:47:19 +0100
Subject: guard write

Guard write call, avoid ignored-return-value warning.

(This is not a false positive: a very subtle attack would consist of
filling up the filesystem so much that only a partial PID is written,
causing the wrong PID to be signaled later.)

(Note that, technically speaking, if only some of the buffer is
written we should retry the rest in a loop.  But in this case, that
seems exceedingly unlikely.)
---
 tayga.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tayga.c b/tayga.c
index 3886831..5027d0a 100644
--- a/tayga.c
+++ b/tayga.c
@@ -439,7 +439,10 @@ int main(int argc, char **argv)
 
 	if (pidfile) {
 		snprintf(addrbuf, sizeof(addrbuf), "%ld\n", (long)getpid());
-		write(pidfd, addrbuf, strlen(addrbuf));
+		if (write(pidfd, addrbuf, strlen(addrbuf)) != strlen(addrbuf)) {
+			slog(LOG_CRIT, "Error, unable to write PID file.\n");
+			exit(1);
+		}
 		close(pidfd);
 	}