From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/15039 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Liu Jie Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] coresight: getcwd: modify the processing of parameters Date: Wed, 18 Dec 2019 10:51:32 +0800 Message-ID: <20191218025132.111684-1-liujie1@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="53642"; mail-complaints-to="usenet@blaine.gmane.org" Cc: , To: Original-X-From: musl-return-15055-gllmg-musl=m.gmane.org@lists.openwall.com Wed Dec 18 04:52:17 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 1ihQNl-000DoC-3U for gllmg-musl@m.gmane.org; Wed, 18 Dec 2019 04:52:17 +0100 Original-Received: (qmail 13379 invoked by uid 550); 18 Dec 2019 03:52:14 -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 30147 invoked from network); 18 Dec 2019 02:52:20 -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:15039 Archived-At: 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 --- 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