diff options
author | Mattias Andrée <maandree@kth.se> | 2017-10-21 18:44:03 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2017-10-21 18:44:03 +0200 |
commit | 389e5c99ec01903fa32fb7d0a178dd416688475e (patch) | |
tree | 5f48f1a592efc911e83493e79330721558923a67 | |
parent | libsbus_receive: check message length to avoid reading outside it (diff) | |
download | sbus-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.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -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); |