From ffb067372bab600555995b284da92cd9f35d42e6 Mon Sep 17 00:00:00 2001 From: lotherk Date: Mon, 16 Nov 2026 16:38:50 +0000 Subject: [PATCH] dtchat: fail cleanly on a zero-byte frame write dc_frame_send now returns -1 instead of looping when write(2) returns 0 for the payload or the trailing newline. --- lib/libDtChat/json.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/libDtChat/json.c b/lib/libDtChat/json.c index 5a41323d..8444ca62 100644 --- a/lib/libDtChat/json.c +++ b/lib/libDtChat/json.c @@ -1261,11 +1261,17 @@ dc_frame_send(int fd, const char *line, size_t len) continue; return -1; } + if (w == 0) + return -1; off += (size_t)w; } - while (write(fd, "\n", 1) < 0) { - if (errno != EINTR) - return -1; + for (;;) { + ssize_t n = write(fd, "\n", 1); + if (n == 1) + break; + if (n < 0 && errno == EINTR) + continue; + return -1; } return 0; }