Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp413092rdb; Mon, 29 Jan 2024 06:16:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IHm71l7fG/TOhW8vk1Z38cZoSmYM8vu3bK2pbrASxQVoiXu1u6XneFlxnTSwWYpfAUSN4KD X-Received: by 2002:a05:6402:2cb:b0:55f:2001:bcd2 with SMTP id b11-20020a05640202cb00b0055f2001bcd2mr663851edx.14.1706537782431; Mon, 29 Jan 2024 06:16:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706537782; cv=pass; d=google.com; s=arc-20160816; b=txzMn+ir31oPtb5RMUFehn3aScDChRx2WhF48mCOiIRz1uhjMNKBVMwkp0zo+9MYAD odycauLGs2bBT8FHSU0gw9DDwQssxWNyynPAEmM7cTODFNs7Mv0nRdsyUxhRYfgUwqwM tc39C7TTocQ5D1K0nV6vx+iiQUMwsrcmtPYani38YraM2iOSXOPuiJGisBS3uspkedsq uveFDKyTQSqL88bt+2HklBPMH5D27hXdD+Puec4Wn7XQXlZDe4iUACSAsJWcFEqEEtzB 3Mb2YvoDKr6jN/IkJ7qgHxJTokiWbeoGzxOgFQ380eOGeGHRGk+m+Tt2v/H3jeFUCUzu eOLQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=PE1f/vPHamhcTWffAYS7v9JGCMah38I8Iko3jx0o1/A=; fh=1pO/fnqlbA1DlSshLp2Kp23nBXobkeZ558bQEuNU3Z8=; b=X2a9ddsffpGjlZU+x2I/wrypHl0E5HJsQAPrTNzn4scd0h1kMop5+visQLv6Hsbmm3 rYcjGf64JkuHqjWN51b+vxH+dN4ZqiPbZeyk6/jv1RE2wytiUfAvhzA7U0WTyqnEqO3E 5vn61AV8H3Pfwnho5vVhMam+0onZj6V96jrUUPzqB/oDx/B6vBQKjmmEwWpHZG0PS6PY h0g7X6D4OXwE/aS2x7HAmAS3ulGdsnUgjokJw8tSTqoo8d3/Uo8a6iZSZ0PzXmADnj8K cw5Ovkzqyiq3H6gCiCfgVuGgF21FaCi68O6OQRtX6+MBLbP7RbL/PEWosXompdJy5i+R B1kQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=sdfg.com.ar); spf=pass (google.com: domain of linux-kernel+bounces-42868-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42868-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ds6-20020a0564021cc600b005585701151csi3613110edb.224.2024.01.29.06.16.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 06:16:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42868-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=sdfg.com.ar); spf=pass (google.com: domain of linux-kernel+bounces-42868-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42868-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6906F1F24437 for ; Mon, 29 Jan 2024 14:16:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 54FC2664B9; Mon, 29 Jan 2024 14:15:47 +0000 (UTC) Received: from alerce.blitiri.com.ar (alerce.blitiri.com.ar [49.12.208.134]) (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 092E86311F for ; Mon, 29 Jan 2024 14:15:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=49.12.208.134 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706537746; cv=none; b=buy9MJ62aG9s0QGXYDOAZKQZu7CvRb7vKypUBNHQiAWiV5scp17IXWSpXDVFF56CTCvNNIf56mWCpKM56/7peWgxnY4usP3QrcEA0CEASylomgvlmmDXjNwhu/EZrLnDTMYN807DccqvoQTUroRoajYOujAWpwXapRMgCvSBC8s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706537746; c=relaxed/simple; bh=mH5A9hH5XvVo2T9vZBvlGm1W3LlxcYXSTb48Acf7hK8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=shWIsQogf5UOyGlku248JW/2Y/ruzv1p2Ye8Ge5Sar/g+RAWrgrQzBAsvX5JKRGHRe5xzLXqk5j0e38rd1HREpiuFcfzdTtU3W9HFOq+LtofINBYA6YEYHQ5ctnbgoTclMExSSJ0Ard5n0BfEgv5N8cnHBMc6szFBAwXkO8ZsTs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sdfg.com.ar; spf=pass smtp.mailfrom=sdfg.com.ar; arc=none smtp.client-ip=49.12.208.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sdfg.com.ar Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sdfg.com.ar Received: from localhost.localdomain by sdfg.com.ar (chasquid) with ESMTPSA tls TLS_AES_128_GCM_SHA256 (over submission, TLS-1.3, envelope from "rodrigo@sdfg.com.ar") ; Mon, 29 Jan 2024 14:15:35 +0000 From: Rodrigo Campos To: Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, Rodrigo Campos Subject: [PATCH 0/4] tools/nolibc: Misc fixes for strlcpy() and strlcat() Date: Mon, 29 Jan 2024 15:15:12 +0100 Message-ID: <20240129141516.198636-1-rodrigo@sdfg.com.ar> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit As requested by Willy and Thomas[1], here go some more fixes and tests for strlcpy() and strlcat(). From the previous discussion, I uderstand that we want to apply the first patch (export strlen()) as is, I've included it again here just in case. Maybe we should just include the -Wl,--gc-sections in the nolibc.h comment about the flags to use when compiling? The rest of the commits are quite simple too, they just: * Fix the return code of both functions * Make sure to always null-terminate the dst buffer * Don't copy more than what size allows us (this handles the size=0 case for free too) All has been checked against the corresponding libbsd implementation[2]. I thought the manpage was clear, but when checking against that, I noted a few twists (like the manpage says the return code of strlcat is strlen(src) + strlen(dst), but it was not clear it is not that if size < strlen(dst). When looking at the libbsd implementation and re-reading the manpage, I understood what it really meant). Let me know what you think :) Best, Rodrigo [1]: https://lore.kernel.org/all/9538a8fe-b92f-42a5-99d1-25969cf51647@sdfg.com.ar/ [2]: https://gitlab.freedesktop.org/libbsd/libbsd.git Rodrigo Campos (4): tools/nolibc/string: export strlen() tools/nolibc: Fix strlcat() return code and size usage tools/nolibc: Fix strlcpy() return code and size usage selftests/nolibc: Add tests for strlcat() and strlcpy() tools/include/nolibc/string.h | 25 +++++++------- tools/testing/selftests/nolibc/nolibc-test.c | 34 ++++++++++++++++++++ 2 files changed, 47 insertions(+), 12 deletions(-) -- 2.43.0