aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-10-21 18:44:03 +0200
committerMattias Andrée <maandree@kth.se>2017-10-21 18:44:03 +0200
commit389e5c99ec01903fa32fb7d0a178dd416688475e (patch)
tree5f48f1a592efc911e83493e79330721558923a67
parentlibsbus_receive: check message length to avoid reading outside it (diff)
downloadsbus-389e5c99ec01903fa32fb7d0a178dd416688475e.tar.gz
sbus-389e5c99ec01903fa32fb7d0a178dd416688475e.tar.bz2
sbus-389e5c99ec01903fa32fb7d0a178dd416688475e.tar.xz
Set errno to ECONNRESET if recv returns 0
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--libsbus.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/libsbus.c b/libsbus.c
index 4a913ec..5b238c8 100644
--- a/libsbus.c
+++ b/libsbus.c
@@ -66,8 +66,11 @@ libsbus_receive(int fd, int flags, char *buf, union libsbus_packet *packet)
char *p;
r = recv(fd, buf, LIBSBUS_BUFFER_SIZE, flags);
- if (r < 0)
+ if (r <= 0) {
+ if (!r)
+ errno = ECONNRESET;
return -1;
+ }
if (r >= 4 && !strncmp(buf, "MSG ", 4)) {
p = memchr(buf, '\0', r);