From nobody Wed Sep 23 11:38:01 2026 X-Original-To: dev-commits-src-all@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 4hqZhp1Jb7z6svYK for ; Wed, 23 Sep 2026 11:38:02 +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 4hqZhn6LcHz4CQr for ; Wed, 23 Sep 2026 11:38:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1790163481; 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=OPvd5ZbwIWM8hA9nBhjtWzHBT03oX4ohI/AHmTqcEK4=; b=R72UtBimtwNRXSkmTO3J2Fi90zBU9klBeRdeX9pUfiarcTKj8YOPZ9+GhwJXrHI358h89N ml9YT+iOQ2ZPtZryT/Ben2sezVji1X2UevLJt9LdvFqlnn8hF6NV7teO3XZIDrNfQ5WJ8p X9HlqgRq/RexLZcTlu5NBJMVX0EKENsmsxIjzM69tDYyUCUdhYxEuJd/yVgcZ3L5hyeogr GKjC6jlUx8sf0JPY6NfR6n4mP3yg57asi9z9/w73ey2FWiKbmM0zP/U2qaTPj+Kv5jP02W maEQewyhuGgfur3/lVvgyPR+Pgd523KV0CRB8lL1qu+CdTfU1fE2qQJ7vp4/MA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1790163481; b=UdwpwzjU4mtmMDpNBI0/mLlGZ/PKvCTTWTI+BDkIiAxUv8mMd+5Yo0vCLm04MbsmFILroN o/DzV4SpZkNo4v9Z2Q1as0Xob/jXFEFOATOFPHYpFI4Zq5CXMxnTyQWk4MoH2gIzipLmhz eh7JWKMxuPBPjiN2HTGtrXVovqMFNxhEWKhvBL1Fmho6TUrxI8ijb5yBOZ/y8MEN/+ZNAR Y913Rqm6H7E8cxySdC2hx85+r3JHc+drFwYiG80qmUpsot/YNEFssGFWTbWT4mgp+W1gRZ Ih3QUqM/LnrrJAe2oIA5aoKKXX2gvMJ73wY6G7wiN6KSmPhS2f5Fe4g1cQzflw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1790163481; 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=OPvd5ZbwIWM8hA9nBhjtWzHBT03oX4ohI/AHmTqcEK4=; b=eX+/YcnTio6moac7ZL4L4aX2T0iJfeMsKwbCsTephbmV64JqY8Vn5NcxFOTjIGc2Pxmfog lR4OX7RldmsdlrRfrfbWIwhaYtLhvGYrlitYJkUTVi1muTj3JSicDZUaIiO2d7e2Xek0e5 pjgz6F1LwQ96yI1QGNKnfbyBB+tKdl8Tyfi5RBjGdvuucWCF93rCuPvMIkp51kGTzkc6+K QMT6p5heer0Okly1eTQSg9EAF8R/8jA55swFqo/ZrwDlwoaQ1s8tNjVn6/qkLbYlshs8hB yAUJgg7wKeQPCGRaUMnbl3y6LiK+ukbABSOfxbSexRd9SufV4U0WiBdw2cUP/A== 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 4hqZhn4r5kzrM0 for ; Wed, 23 Sep 2026 11:38:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 45783 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 23 Sep 2026 11:38:01 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Certner Subject: git: 72bb9eb7b6de - main - pwd(1): De-obfuscate, style(9) List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 72bb9eb7b6decc34f343bdcbf0a8df0c73f9edd4 Auto-Submitted: auto-generated Date: Wed, 23 Sep 2026 11:38:01 +0000 Message-Id: <6ab3ba19.45783.77c242b8@gitrepo.freebsd.org> The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=72bb9eb7b6decc34f343bdcbf0a8df0c73f9edd4 commit 72bb9eb7b6decc34f343bdcbf0a8df0c73f9edd4 Author: Olivier Certner AuthorDate: 2026-09-07 16:09:54 +0000 Commit: Olivier Certner CommitDate: 2026-09-23 11:37:45 +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 --- 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); }