From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14871 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Zhang Tianci Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] aio: aio_read() may not return error for invalid argument Date: Sun, 27 Oct 2019 13:45:37 +0800 Message-ID: <20191027054537.166030-1-zhangtianci1@huawei.com> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="218409"; mail-complaints-to="usenet@blaine.gmane.org" Cc: , , To: Original-X-From: musl-return-14887-gllmg-musl=m.gmane.org@lists.openwall.com Sun Oct 27 11:34:55 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1iOfss-000uhB-7r for gllmg-musl@m.gmane.org; Sun, 27 Oct 2019 11:34:54 +0100 Original-Received: (qmail 27724 invoked by uid 550); 27 Oct 2019 10:33:22 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 3319 invoked from network); 27 Oct 2019 05:48:43 -0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [10.113.189.241] X-CFilter-Loop: Reflected Xref: news.gmane.org gmane.linux.lib.musl.general:14871 Archived-At: 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 --- 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