[LTP] [PATCH 13/15] ujson: writer: Set errno when a flush fails
Andrea Cervesato
andrea.cervesato@suse.de
Mon Oct 5 15:25:41 CEST 2026
From: Andrea Cervesato <andrea.cervesato@suse.com>
ujson_writer_file_close() uses errno to decide whether flushing the
buffered data failed. out_writer_file_write() can fail without setting
errno, when write() returns 0 or more bytes than requested, so close
could report success even though data was lost. Set errno to EIO in
these cases.
Fixes: c50a0e0751c8 ("libs: Vendor ujson library")
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
libs/ujson/ujson_writer.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libs/ujson/ujson_writer.c b/libs/ujson/ujson_writer.c
index 15faca9be..49f73e436 100644
--- a/libs/ujson/ujson_writer.c
+++ b/libs/ujson/ujson_writer.c
@@ -399,11 +399,15 @@ static int out_writer_file_write(ujson_writer *self, int fd, const char *buf, ss
ssize_t ret = write(fd, buf, buf_len);
if (ret <= 0) {
err(self, "Failed to write to a file");
+ /* ujson_writer_file_close() relies on errno */
+ if (!ret)
+ errno = EIO;
return 1;
}
if (ret > buf_len) {
err(self, "Wrote more bytes than requested?!");
+ errno = EIO;
return 1;
}
--
2.51.0
More information about the ltp
mailing list