From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5D6F3A5434 for ; Mon, 22 Jun 2026 10:17:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782123466; cv=none; b=b18kqZfBycVucrXViE6ee5ifZLyHiv7GC4nRrrXkiP0kpo7sBMBTylSnZ7f6+gyexIv5/yWDxUILwoI1Y0azSgClgdQYS5GWSP3OMUKHOcv/H3FbeiQ4n9QQW10vKfpjKww3FSpPW1csde+SjtM+ZeoAzAGmDoFOivBrQ9TMuWw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782123466; c=relaxed/simple; bh=QnnTNtwjLBfbxy8zzPGWSQ8HI5pO4Y+zssCxz1/puYk=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=G0w8OvTFpAGVgqR6BgiYjdJUcb2WferEIDX7I52pcAAFH9TG8Va2kL/ys9R5QRQfmHieGpO3MbMKSzvr8WWp/1g4xM/ic/K7Xj69niA+O+qD3fSLvisq4U1ugyBwAQPWaFr1HmXDKSNIxCRUJoSehZ/tpNHD5mr+TCpMzSSDDf8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YDf7a0B9; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YDf7a0B9" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-4624a44e152so3522905f8f.2 for ; Mon, 22 Jun 2026 03:17:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782123463; x=1782728263; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=FdT78b4A5DNqBgEoFgT0uFGWS3MO+ivE5ufwX9sjclk=; b=YDf7a0B9OrtwSvrXmYdYHbf2u98oe0dOCxJJfv5L6jurZYoq5XR0TNUN9c3R4HJIgK UA4Jm42gg+lTrSPMOjbW2hE3iiWrMM5l+j+Y7gUl2fTfMtFqIlJJrTCJl3DaV1k3y6iU q9ttqSEDizjgxBTHOocxcm4/clyQy5db4Qxdxhddseyd8cguT8OQjw3UGfQhI9r+pGkX ktf9Cu+82gFjeyB/SGlFAOhVVsaQG4wnQ5QJeLMPzPprsD40t5exMKrijBXpT2R0db6m RhKk6LxazT7wOKDnpahsMFeWN3WbSLaaghVika5SuEvJKE+z1GImXDuRXR3QlTtlHhrO g32w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782123463; x=1782728263; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=FdT78b4A5DNqBgEoFgT0uFGWS3MO+ivE5ufwX9sjclk=; b=DOwV6WREg+mbbVXsTH7RPbBAbIXfe7BJoLzETHwSCX+mCmiybaP1UweE1DVQFEkaef 7CJEsg5uBMgTMKQxUI2Oc7VtVM/hqliBF98GpV/ZL53d1HivlJpnvRaNw+dRgb4TYWbr IV9ezJcCkjLSsQjrnCAKq1jgjXzFGkXK2Evr4hVN9SoEd7O33RKS5/4wdyx/Ae2wNMh7 QgJwAKCZ8No8Sg7mi/9bpSO//joG6A1diA3fnKnbI3gBkczXBNJ39KcP88zpqZwWvgt/ KNQJSi4Zgv6+ygv1CVcN3XuZWRRrLCEjlpCpv+ZPR5I57LwXMFUR7UiK9LmB69AlPpIZ PHdg== X-Forwarded-Encrypted: i=1; AFNElJ9A+57ng8cr7/BiRaVYxo26233Cv2zPlQeVoe0j4CbfoRwlimUQnr+IH16D+DJbGpyX+7nx1WCmctUKB10=@vger.kernel.org X-Gm-Message-State: AOJu0Yxx+Crz4g3jAjhzpCQGWcUSrc/74o7U7Yt7usdTvJH/szEodx3s +qG+8B4H/aTdhwgC9QJmz8kbckY4K6RyF4jcvn9/z0wiVi43uVNEK2PC X-Gm-Gg: AfdE7clmcSTLPT+6uT/gYXWoMkGdsEq7se8L4l+VBC+LAS8azQ+LoZnPlRzq3Rrv6H9 rCAti72yniPS8syTCdhYEQ57uTRmogCJNWOgZhygRQ0UMIWBotebU8oMiLm+0DhiiflhnENnARb KY8EHfsUkbJAKnNxAPzLoPBP4xjXwQYYet/pXlTNkpcMolxPx76G3AOlERd7HzzkETFtkW83WEK qTu6f/8e0xtb0X0NR0mZf1Wr2F3rFOHUBAYirh7TI7+1hxutr5qIGvxtdJCjcPTnk4ykC2tKrZI Fjy6suv78LSBBP7dBrDswv8FNyXd00p/dsL7Ksw4q4bN9MnLw4uAvLNRokR6kykboInVkm75f6d 6hCKkXTh0G+0EnwoEdmqc8n0P3csx7uwFQv30iboKMS9H2PCmnF1JVpy9k+B/KaK5+sBnoD+rkI WhcM7giudo8yzB+sdUe7fkyUTHc+IQ0QsA6Kkd4FjhTE5uWiTeng== X-Received: by 2002:a05:600c:8011:b0:492:2ffd:8f8 with SMTP id 5b1f17b1804b1-49240e19b44mr236492405e9.15.1782123462838; Mon, 22 Jun 2026 03:17:42 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-46666788226sm24991696f8f.23.2026.06.22.03.17.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2026 03:17:42 -0700 (PDT) Date: Mon, 22 Jun 2026 11:17:40 +0100 From: David Laight To: Andreas Hindborg Cc: Kees Cook , linux-hardening@vger.kernel.org, Arnd Bergmann , linux-kernel@vger.kernel.org, Breno Leitao Subject: Re: [PATCH next] fs: Replace strcpy(s, "../") with memcpy(s, "../", 4) Message-ID: <20260622111740.63820fc2@pumpkin> In-Reply-To: <87se6fdkb2.fsf@t14s.mail-host-address-is-not-set> References: <20260606202633.5018-5-david.laight.linux@gmail.com> <874iiyg5kj.fsf@t14s.mail-host-address-is-not-set> <20260619143438.495c1780@pumpkin> <87se6fdkb2.fsf@t14s.mail-host-address-is-not-set> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 22 Jun 2026 10:57:21 +0200 Andreas Hindborg wrote: > David Laight writes: ... > > I just looked at the code again, the final '- 1' on the 'size = ...' > > line looks very odd. > > It's to leave space for a null char at the end. `fill_item_path` writes > the path from the last segment to the first. But wouldn't that be a '+ 1' ? It might be alright because (IIRC) the length is initialised to one in the helper function. > > > I wonder if it would be simpler to merge all three functions into > > something with a single loop that builds the name/name part backwards > > from the end of the buffer while adding "../" on the front and then > > calling memmove() to put the two together. > > The current implementation is difficult to read for sure. It would be > nice if we can make it more simple to parse. I dislike code that does two passes, one to work out the size and the second to do the work. All too easy for them to get out of sync. One of the pathname functions (but I don't know if this code is used for it) lets the string start part way down the supplied buffer. If it is that case then it could be a lot simpler. It also wouldn't do any hard to try embedding the 'char name[PATH_MAX]' in a structure - so the size is passed implicitly and the compiler can check and humans know what they can do. David > > Best regards, > Andreas Hindborg >