From patchwork Mon Jan 29 14:15:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Campos X-Patchwork-Id: 19599 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp594229dyb; Mon, 29 Jan 2024 06:16:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMI2K9O7zbVq3yqsTdSOJ5nhp+Uhm8wG3U3vlUTePO/zE1dKwVcpWUluAqaE3u7+yVXU0v X-Received: by 2002:a05:6402:22ac:b0:55e:fb9b:e0dc with SMTP id cx12-20020a05640222ac00b0055efb9be0dcmr2033302edb.37.1706537807634; Mon, 29 Jan 2024 06:16:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706537807; cv=pass; d=google.com; s=arc-20160816; b=I8509Zi+k1GJo4ZIQcGzuI+Gq8qI+oC31iUsBD7ndq7Cn4IUYDzgZhwscYgpBVGwOJ BJqlIz+mAl6fvGx6FVN62BoyftGTDTMABT6CmiOQEkGVE7i0gcdPNFoKGPjKWSUNjSfz 40vDgYqiVTohGEM9+VmoWKw8kXvITlB5UpXvGQqNlv6N88POHXs/NoPTuAj+2qSX3gSb +Jvq0A6bA22h7VwaY0nRPZVtFSSDl8R315Cx6ZRuDUm/RJukyxf4Ng+bAz7Nrehu1XYF /xvT43l9Z1PhhJwdUCcn1b5hBdXMCeQmfY8Eack8Y/sriA8IuFz3QIa8hG4YwD11npHv pHVw== 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42868-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 6-20020a508e46000000b0055a1e7baedbsi3527136edx.579.2024.01.29.06.16.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 06:16:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42868-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42868-ouuuleilei=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 3D5991F22DB4 for ; Mon, 29 Jan 2024 14:16:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7595966B54; Mon, 29 Jan 2024 14:15:48 +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_Wei=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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789434587944990006 X-GMAIL-MSGID: 1789434587944990006 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(-)