Recently Written · git

sacc

Mirror of git://bitreich.org/sacc, the sacc gopher client from bitreich.org.

git clone https://github.com/equwal/sacc

Log | Files | Refs


commit 20a51bafd3906aa0337fe221d0981293d94370a5
Michael Forney <mforney@mforney.org>
2024-03-19 14:52:09 -0700

Avoid zero-length iowrite

iowrite with bs==0 results in either a zero-length write() or
tls_write().

The former is unspecified by POSIX[0]:
> If nbyte is zero and the file is not a regular file, the results
> are unspecified.

The latter is not explicitly disallowed by tls_write(3), but libressl
implements tls_write with a call to SSL_write, which is documented
to have undefined behavior[1]:
> When calling SSL_write() with num=0 bytes to be sent, the behaviour
> is undefined.

[0] https://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html
[1] https://man.openbsd.org/SSL_write.3

 sacc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sacc.c b/sacc.c
index 7016554..700d4ec 100644
--- a/sacc.c
+++ b/sacc.c
@@ -535,10 +535,10 @@ sendselector(struct cnx *c, const char *selector)
 	msg = p = xmalloc(ln);
 	snprintf(msg, ln--, "%s\r\n", selector);
 
-	while ((n = iowrite(c, p, ln)) > 0) {
+	while (ln && (n = iowrite(c, p, ln)) > 0) {
 		ln -= n;
 		p += n;
-	};
+	}
 
 	free(msg);
 	if (n == -1)