sacc

sacc (saccomys): simple gopher client.
Log | Files | Refs | LICENSE

commit 20a51bafd3906aa0337fe221d0981293d94370a5
parent 21d46d603a3697f04072e4c0edb0076b4a215a2e
Author: Michael Forney <mforney@mforney.org>
Date:   Tue, 19 Mar 2024 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

Diffstat:
Msacc.c | 4++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 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)