Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Wed, 18 Dec 2019 10:51:32 +0800
From: Liu Jie <liujie1@...wei.com>
To: <musl@...ts.openwall.com>
CC: <yunlong.song@...wei.com>, <liujie1@...wei.com>
Subject: [PATCH] coresight: getcwd: modify the processing of parameters

According to POSIX 2008, the getcwd() function shall fail if:
[EINVAL] The size argument is 0.
[ERANGE] The size argument is greater than 0, but is smaller
         than the length of the string +1.
The size should not be assigned, even if buf is NULL, otherwise
the error ERANGE cannot be correctly judged.

Signed-off-by: Liu Jie <liujie1@...wei.com>
---
 src/unistd/getcwd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/unistd/getcwd.c b/src/unistd/getcwd.c
index f407ffe0..ee2e97e9 100644
--- a/src/unistd/getcwd.c
+++ b/src/unistd/getcwd.c
@@ -9,8 +9,8 @@ char *getcwd(char *buf, size_t size)
 	char tmp[buf ? 1 : PATH_MAX];
 	if (!buf) {
 		buf = tmp;
-		size = sizeof tmp;
-	} else if (!size) {
+	}
+	if (!size) {
 		errno = EINVAL;
 		return 0;
 	}
-- 
2.17.1

Powered by blists - more mailing lists

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