From: Vincent Bernat Date: Sun, 31 Aug 2014 05:31:57 +0000 (+0200) Subject: lib: correctly handle read failure X-Git-Tag: 0.7.11~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=62f2faac3c69eca215bb4f09182874d9ba27fca5;p=thirdparty%2Flldpd.git lib: correctly handle read failure --- diff --git a/NEWS b/NEWS index 864ca2bb..88633e60 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ lldpd (0.7.11) * Features: + Ship bash and zsh completion. + * Fix: + + Handle correctly read failures in liblldpctl. lldpd (0.7.10) * Features: diff --git a/src/lib/connection.c b/src/lib/connection.c index f7525704..ee6e92ee 100644 --- a/src/lib/connection.c +++ b/src/lib/connection.c @@ -67,7 +67,7 @@ sync_recv(lldpctl_conn_t *lldpctl, const uint8_t *data, size_t length, void *user_data) { struct lldpctl_conn_sync_t *conn = user_data; - size_t nb; + ssize_t nb; size_t remain, offset = 0; if (conn->fd == -1 && @@ -78,9 +78,11 @@ sync_recv(lldpctl_conn_t *lldpctl, remain = length; do { - if ((nb = read(conn->fd, (void*)data + offset, remain)) == -1 && - (errno == EAGAIN || errno == EINTR)) - continue; + if ((nb = read(conn->fd, (void*)data + offset, remain)) == -1) { + if (errno == EAGAIN || errno == EINTR) + continue; + return LLDPCTL_ERR_CALLBACK_FAILURE; + } remain -= nb; offset += nb; } while (remain > 0 && nb > 0);