summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2017-11-27 23:04:27 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2017-11-27 23:04:27 +0000
commitd67535b7fcef2f6f465baa8aae0d46eb159b9522 (patch)
tree2eaf898cc8b883c94db3aa2bf06a07eb72441faf /usr.sbin
parentce42d55fedf6e092dfaed5cb3c30f0f4fa04c10d (diff)
lseek/read is racy when there is multiple consumers. Use pread instead.
Solves the startup issues seen by bluhm@. pread idea from guenther@. While there save the errno in the error case. OK bluhm@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/relayd/relay.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c
index a82f727efbf..3361cdc12cf 100644
--- a/usr.sbin/relayd/relay.c
+++ b/usr.sbin/relayd/relay.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relay.c,v 1.231 2017/11/27 21:09:55 claudio Exp $ */
+/* $OpenBSD: relay.c,v 1.232 2017/11/27 23:04:26 claudio Exp $ */
/*
* Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -2580,15 +2580,14 @@ relay_load_fd(int fd, off_t *len)
struct stat st;
off_t size;
ssize_t rv;
+ int err;
if (fstat(fd, &st) != 0)
goto fail;
size = st.st_size;
if ((buf = calloc(1, size + 1)) == NULL)
goto fail;
- if (lseek(fd, 0, SEEK_SET) != 0)
- goto fail;
- if ((rv = read(fd, buf, size)) != size)
+ if ((rv = pread(fd, buf, size, 0)) != size)
goto fail;
close(fd);
@@ -2597,8 +2596,10 @@ relay_load_fd(int fd, off_t *len)
return (buf);
fail:
+ err = errno;
free(buf);
close(fd);
+ errno = err;
return (NULL);
}