From: Zhang Tianci <zhangtianci1@huawei.com>
To: <musl@lists.openwall.com>
Cc: <zhangtianci1@huawei.com>, <yunlong.sun@huawei.com>,
<zhangzhikang1@huawei.com>
Subject: [PATCH] aio: aio_read() may not return error for invalid argument
Date: Sun, 27 Oct 2019 13:45:37 +0800 [thread overview]
Message-ID: <20191027054537.166030-1-zhangtianci1@huawei.com> (raw)
For aio_read(0, buf, 0, -1) will return success.
Because STDIN is unseekable, so aio_read() will call read(0, buf, 0),
but read(0, buf, 0) will not return error.
So we should check that whether aio_offset is valid or not when the
file is unseekable.
Signed-off-by: Zhang Tianci <zhangtianci1@huawei.com>
---
src/aio/aio.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/aio/aio.c b/src/aio/aio.c
index 6d34fa86..d30526e4 100644
--- a/src/aio/aio.c
+++ b/src/aio/aio.c
@@ -242,7 +242,16 @@ static void *io_thread_func(void *ctx)
ret = q->append ? write(fd, buf, len) : pwrite(fd, buf, len, off);
break;
case LIO_READ:
- ret = !q->seekable ? read(fd, buf, len) : pread(fd, buf, len, off);
+ if (!q->seekable) {
+ if (off < 0) {
+ ret = -1;
+ errno = EINVAL;
+ } else {
+ ret = read(fd, buf, len);
+ }
+ } else {
+ ret = pread(fd, buf, len, off);
+ }
break;
case O_SYNC:
ret = fsync(fd);
@@ -253,7 +262,7 @@ static void *io_thread_func(void *ctx)
}
at.ret = ret;
at.err = ret<0 ? errno : 0;
-
+
pthread_cleanup_pop(1);
return 0;
--
2.17.1
next reply other threads:[~2019-10-27 5:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-27 5:45 Zhang Tianci [this message]
2019-10-27 15:17 ` Rich Felker
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=20191027054537.166030-1-zhangtianci1@huawei.com \
--to=zhangtianci1@huawei.com \
--cc=musl@lists.openwall.com \
--cc=yunlong.sun@huawei.com \
--cc=zhangzhikang1@huawei.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).