Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Sun, 27 Oct 2019 13:45:37 +0800
From: Zhang Tianci <zhangtianci1@...wei.com>
To: <musl@...ts.openwall.com>
CC: <zhangtianci1@...wei.com>, <yunlong.sun@...wei.com>,
	<zhangzhikang1@...wei.com>
Subject: [PATCH] aio: aio_read() may not return error for invalid argument

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@...wei.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

Powered by blists - more mailing lists

Your e-mail address:

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.