From 7882ba423cd87569f9c9361fa999917e9ced1083 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 13 Mar 2020 11:48:35 -0700 Subject: [PATCH] iostream: protect write side against bad custom IO interfaces too This is the same as the previous commit, just for the write side error handling. If we have a bad custom IO low-level driver that returns DC_STATUS_SUCCESS with zero bytes written, and we have a write() user that isn't ready for partial writes, we just consider that an IO error. Signed-off-by: Linus Torvalds --- src/iostream.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/iostream.c b/src/iostream.c index 7d0040d..376c9e4 100644 --- a/src/iostream.c +++ b/src/iostream.c @@ -260,6 +260,9 @@ dc_iostream_write (dc_iostream_t *iostream, const void *data, size_t size, size_ if (status != DC_STATUS_SUCCESS) return status; + if (!nbytes) + return DC_STATUS_IO; + data = (void *)(nbytes + (char *)data); size -= nbytes; }