From 62f2faac3c69eca215bb4f09182874d9ba27fca5 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 31 Aug 2014 07:31:57 +0200 Subject: [PATCH] lib: correctly handle read failure --- NEWS | 2 ++ src/lib/connection.c | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) 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); -- 2.39.5