From nobody Thu Oct 08 12:21:39 2026 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4j0pyC5C85z6vZ8t for ; Thu, 08 Oct 2026 12:21:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4j0pyC49Kpz4MSD for ; Thu, 08 Oct 2026 12:21:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791462099; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=canLE/wWfogJAmGmOpVPaDeEfV8C2RQiovZsmwqZ918=; b=yZynq+4o76Kh4dr3njr6djjXE5RJEl7fvOZpM6KLySD70F43ckQ5oHGjl7gUAmmpASHlFf c7ZCDaihq8CFfFg0kloBTaRnprezSaPRmnlrMDNPR3+PALg1APtK8Vz2o/lPOouGnM8AGx Sf7LAeTWDELOeYMHjH+JDzfxE9uln+SnBJfXBjWwb5LZ6eXl/MTj5ipf8SxGj6PDC22oDb 3Yrq6uDzFeCt4ikWkxVKV6xgnHEuuG4Rhlcl3QRFwi3O5k4nMhkarlStP7GUnOCOOf+LTq DpL1JzP0ysMBacsTj334GWvGprWOeMR3uhgQajHIxbYOSJD+l0TfPW1GxiROcw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1791462099; b=qUCYO3FwFTRt2Ri/ol3ZEp7MfYI/5gcWp8vTeUiQl1FhCGXkFETp+1CHumYv8HyTyF2OO9 WusLfcc55aQuh7wcpUtANjt7nrqaB6Mqf88Oa+dTcDx7eEISYHVA/Lb7hYmiz97Bs4GC7S Y3+cBSbJe2f1J+imAZTKWTvrsKpXU2zm47MznJkWKIbUf/stet+Tcyj8/rZB1KDtWuLQeJ 1IluSgab0yeznG9w1JU0srQrYGZRhTtWym924XudyKdtrPRr/i5NCIDj4/LgqMFqjHY/MS EdFd0KmYqzI6RPEQvkMy++CntPP+zkx4Qtp7AdNhk3afaGno+dMobzD8Q3qEkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791462099; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=canLE/wWfogJAmGmOpVPaDeEfV8C2RQiovZsmwqZ918=; b=krH2ooUQZ094ma+f5s5bXWtZD1+Y8CPuOBjsW+O0DuvsIgzBHYCxBI7r8b5QBdOZwCcx19 DgZse07VVCRc1xUnO2x50ua18DLC6jx8olhcSQQrDfpIJ4I9q2+O+99i98991As3yLxmAU KLNAOYxd3rCdnfuwXXRp0TW/UPMa2ScTyaamNdCVC120JhX0oTTDuu8cXtKqlMZ+hxj5Kg 24H//NXlJqRBX9nbCLUFJXPpjlkC8ldnEuGIXl40lI8inno0nFc7yNGlX/oXq2e1GiVOvY vr/oBp+c8ROViVY/4Mue1sXxaToyQk1GDCVLKc/mBD7kRDTRAmM/sNcwb9wXIw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4j0pyC3Cd7zgYt for ; Thu, 08 Oct 2026 12:21:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1d94e by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 08 Oct 2026 12:21:39 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: 3d64b7fc9375 - stable/15 - pwd(1): De-obfuscate, style(9) List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 3d64b7fc93759158cca147fa964443209ac8dfe8 Auto-Submitted: auto-generated Date: Thu, 08 Oct 2026 12:21:39 +0000 Message-Id: <6ac78ad3.1d94e.4a9f2b55@gitrepo.freebsd.org> The branch stable/15 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=3d64b7fc93759158cca147fa964443209ac8dfe8 commit 3d64b7fc93759158cca147fa964443209ac8dfe8 Author: Olivier Certner AuthorDate: 2026-09-07 16:09:54 +0000 Commit: Olivier Certner CommitDate: 2026-10-08 12:20:00 +0000 pwd(1): De-obfuscate, style(9) In getcwd_logical(), test for a '.' or '..' component in one of the most straightforward and intelligible ways possible. In particular, this removes a superfluous re-test of the the component's first character being '.' when the first one did not pass and, more importantly, prevents the second test from relying on a side-effect in the first. While here, for better clarity, replace the loop that searches for '/' with a simple call to strchrnul(). Add high-level comments about what is going on. While here, test explicitly that pointed 'char' values are not 0 ('\0') (style(9)). While here, separate the successive steps of getcwd_logical() with blank lines. No functional change (intended). Discussed with: emaste Fixes: 2df923c5d2d0 ("pwd: Clean up and adopt POSIX semantics") MFC after: 3 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D59709 (cherry picked from commit 72bb9eb7b6decc34f343bdcbf0a8df0c73f9edd4) --- bin/pwd/pwd.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bin/pwd/pwd.c b/bin/pwd/pwd.c index 2bbf5457ec17..f619024fdcff 100644 --- a/bin/pwd/pwd.c +++ b/bin/pwd/pwd.c @@ -33,33 +33,40 @@ #include #include +#include #include #include #include #include +#include #include static char * getcwd_logical(void) { struct stat log, phy; - char *pwd, *p, *q; + char *pwd, *s, *e; /* $PWD is set and absolute */ if ((pwd = getenv("PWD")) == NULL || *pwd != '/') return (NULL); + /* $PWD does not contain /./ or /../ */ - for (p = pwd; *p; p = q) { - for (q = ++p; *q && *q != '/'; q++) - /* nothing */; - if ((*p == '.' && q == ++p) || - (*p == '.' && q == ++p)) + e = pwd; + do { + assert(*e == '/'); + s = e + 1; /* Beginning of next component (may point to NUL). */ + /* Search for the component's end. */ + e = strchrnul(s, '/'); + if (s[0] == '.' && (s + 1 == e || (s[1] == '.' && s + 2 == e))) return (NULL); - } + } while (*e != '\0'); + /* $PWD refers to the current directory */ if (stat(pwd, &log) != 0 || stat(".", &phy) != 0 || log.st_dev != phy.st_dev || log.st_ino != phy.st_ino) return (NULL); + return (pwd); }