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 2/4] alfred: avoid endless-loop when reading data from stdin fails
Date: Fri, 31 Jul 2026 09:40:14 +0200 [thread overview]
Message-ID: <20260731-bugfixes-client-v1-2-83d8c7a26421@narfation.org> (raw)
In-Reply-To: <20260731-bugfixes-client-v1-0-83d8c7a26421@narfation.org>
alfred_client_set_data() read the dataset from stdin in a loop guarded only
by feof(). fread() returns 0 not only at end of file but also on a read
error. A persistent read error therefore made 'alfred -s' spin forever
without making progress.
Stop reading as soon as fread() cannot deliver any data, which covers both
end of file and read errors.
Fixes: 23359bbf72aa ("alfred: initial commit")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
client.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/client.c b/client.c
index 9fa9f00..1967f69 100644
--- a/client.c
+++ b/client.c
@@ -153,6 +153,17 @@ int alfred_client_set_data(struct globals *globals)
len = sizeof(*push) + sizeof(*data);
while (!feof(stdin)) {
ret = fread(&buf[len], 1, sizeof(buf) - len, stdin);
+ if (ret == 0) {
+ if (ferror(stdin)) {
+ fprintf(stderr, "%s: failed to read data from stdin\n",
+ __func__);
+ unix_sock_close(globals);
+ return -1;
+ }
+
+ break;
+ }
+
len += ret;
if (sizeof(buf) == len)
--
2.47.3
next prev parent reply other threads:[~2026-07-31 7:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 7:40 [PATCH 0/4] alfred: client: random fixes Sven Eckelmann
2026-07-31 7:40 ` [PATCH 1/4] alfred: fix error code from unix_sock_req_data_reply Sven Eckelmann
2026-07-31 7:40 ` Sven Eckelmann [this message]
2026-07-31 7:40 ` [PATCH 3/4] alfred: close the listening socket on daemon setup errors Sven Eckelmann
2026-07-31 7:40 ` [PATCH 4/4] alfred: handle short reads when waiting for daemon answer 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=20260731-bugfixes-client-v1-2-83d8c7a26421@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox