mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] coresight: getcwd: modify the processing of parameters
@ 2019-12-18  2:51 Liu Jie
  2019-12-18  3:52 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Liu Jie @ 2019-12-18  2:51 UTC (permalink / raw)
  To: musl; +Cc: yunlong.song, liujie1

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-12-18  3:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-18  2:51 [PATCH] coresight: getcwd: modify the processing of parameters Liu Jie
2019-12-18  3:52 ` Rich Felker

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).