From: Jouni Roivas <jouni.roivas@tuxera.com>
To: <musl@lists.openwall.com>, <dalias@libc.org>
Subject: [musl] [PATCH v2] avoid writing two iov in __stdio_write backend when not needed
Date: Mon, 12 Oct 2020 19:43:42 +0300 [thread overview]
Message-ID: <20201012164342.2987876-1-jouni.roivas@tuxera.com> (raw)
In-Reply-To: <20201012163031.GA2950028@tuxera.com>
formally, calling writev with a zero-length first iov component should
behave identically to calling write on just the second component, but
presence of a zero-length iov component has triggered bugs in some
kernels.
---
src/stdio/__stdio_write.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/stdio/__stdio_write.c b/src/stdio/__stdio_write.c
index d2d89475..eedce03a 100644
--- a/src/stdio/__stdio_write.c
+++ b/src/stdio/__stdio_write.c
@@ -11,6 +11,10 @@ size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len)
size_t rem = iov[0].iov_len + iov[1].iov_len;
int iovcnt = 2;
ssize_t cnt;
+ if (iov[0].iov_len == 0) {
+ iov++;
+ iovcnt--;
+ }
for (;;) {
cnt = syscall(SYS_writev, f->fd, iov, iovcnt);
if (cnt == rem) {
--
2.25.1
prev parent reply other threads:[~2020-10-12 16:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-12 12:59 [musl] [PATCH] Skip writing first iovec if it's empty Jouni Roivas
2020-10-12 15:02 ` Rich Felker
2020-10-12 16:30 ` Jouni Roivas
2020-10-12 16:43 ` Jouni Roivas [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201012164342.2987876-1-jouni.roivas@tuxera.com \
--to=jouni.roivas@tuxera.com \
--cc=dalias@libc.org \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).