From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Sven Eckelmann <sven@narfation.org>
Subject: [PATCH 4/8] alfred: vis: handle short reads on the unix socket
Date: Tue, 28 Jul 2026 18:01:33 +0200 [thread overview]
Message-ID: <20260728-bugfixes-vis-v1-4-2540447c8a67@narfation.org> (raw)
In-Reply-To: <20260728-bugfixes-vis-v1-0-2540447c8a67@narfation.org>
The answer of the alfred daemon is received over a SOCK_STREAM unix socket
which doesn't preserve message boundaries. read() can therefore return less
than the requested number of bytes. Such a short read was treated like an
end of stream, the current packet was dropped and the answer loop
terminated.
Retry the read until the requested amount of data, end of stream or a real
error was received (ignoring temporary interruptions EINTR).
Fixes: 2e3e312f7757 ("alfred: add vis")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
vis/vis.c | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/vis/vis.c b/vis/vis.c
index d529583..33fa692 100644
--- a/vis/vis.c
+++ b/vis/vis.c
@@ -694,6 +694,29 @@ static int vis_request_data(struct globals *globals)
return globals->unix_sock;
}
+static ssize_t read_full(int fd, void *buf, size_t count)
+{
+ size_t read_len = 0;
+ uint8_t *pos = buf;
+ ssize_t ret;
+
+ while (read_len < count) {
+ ret = read(fd, pos + read_len, count - read_len);
+ if (ret < 0) {
+ if (errno == EINTR)
+ continue;
+
+ return ret;
+ }
+
+ if (ret == 0)
+ break;
+
+ read_len += ret;
+ }
+
+ return read_len;
+}
static struct vis_v1 *vis_receive_answer_packet(int sock, uint16_t *len)
{
@@ -704,11 +727,11 @@ static struct vis_v1 *vis_receive_answer_packet(int sock, uint16_t *len)
int ret;
int l;
- ret = read(sock, buf, sizeof(*tlv));
+ ret = read_full(sock, buf, sizeof(*tlv));
if (ret < 0)
return NULL;
- if (ret < (int)sizeof(*tlv))
+ if (ret < (int)sizeof(*tlv))
return NULL;
tlv = (struct alfred_tlv *)buf;
@@ -726,7 +749,7 @@ static struct vis_v1 *vis_receive_answer_packet(int sock, uint16_t *len)
return NULL;
/* read the rest of the packet */
- ret = read(sock, buf + sizeof(*tlv), l);
+ ret = read_full(sock, buf + sizeof(*tlv), l);
if (ret < l)
return NULL;
--
2.47.3
next prev parent reply other threads:[~2026-07-28 17:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-28 16:01 [PATCH 0/8] alfred: vis: random fixes Sven Eckelmann
2026-07-28 16:01 ` [PATCH 1/8] alfred: vis: reject too long unix socket paths Sven Eckelmann
2026-07-28 16:01 ` [PATCH 2/8] alfred: vis: keep interface names always in heap Sven Eckelmann
2026-07-28 16:01 ` [PATCH 3/8] alfred: vis: return query_rtnl_link error on failed send Sven Eckelmann
2026-07-28 16:01 ` Sven Eckelmann [this message]
2026-07-28 16:01 ` [PATCH 5/8] alfred: vis: report failures while reading the answer Sven Eckelmann
2026-07-28 16:01 ` [PATCH 6/8] alfred: vis: don't drop the rest of the answer for a bogus dataset Sven Eckelmann
2026-07-28 16:01 ` [PATCH 7/8] alfred: vis: fix jsondoc output for nodes without vis entries Sven Eckelmann
2026-07-28 16:01 ` [PATCH 8/8] alfred: vis: skip originators with unresolvable hard interface Sven Eckelmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260728-bugfixes-vis-v1-4-2540447c8a67@narfation.org \
--to=sven@narfation.org \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.