From patchwork Sun Feb 18 19:51:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rodrigo Campos X-Patchwork-Id: 20568 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp928794dyc; Sun, 18 Feb 2024 11:51:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXeqXbHubSVZgrApmHjmoq27InPuAoWuSRKMO2BXecm/JnZ70oKvJdR7gw5rAjO81rNaXZH7ghok36312Ue/L7A037rhQ== X-Google-Smtp-Source: AGHT+IHARFvEyG58nwnWOnWfgkz3bUoensGwoHIbstliS6gyzRaHQMT2L7aa4dX5U1NRbekXu0Rz X-Received: by 2002:a05:6870:d8cf:b0:21a:8178:5505 with SMTP id of15-20020a056870d8cf00b0021a81785505mr12791963oac.40.1708285908027; Sun, 18 Feb 2024 11:51:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708285907; cv=pass; d=google.com; s=arc-20160816; b=yg5jbipDPwPofM2rd0eeTvU4Yv6CHB/lL0F1HRYfvXiSXdWzxb0/rTB9sc38Fd2UPV tOFg8IaepKPkybg46OqaannOwZiIp5/h43tgsEFLrtMfUNlpuUO9wu/bkFjL1giiN56r qK4tJi6WkQp9ghiVfC5WqkLwbj0MVV5J4dyGVznonO3+ZH8ghgM1bI1cIYtTawvzZnTr woPiOJLW30m1ZyOc2IQZfgcTgOI1o796hljxBKDfahp5ChCMmzCyWpwsAyEHVxypvIIg ntvMGD0pvo9aEN7JJ+uQeCzGXOwh/f7w9eJgUMQntJ5Jl377DkLsIuih86FXfdiAMIrl m+7g== 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=6BmoG14eQ7MEI6SQnmxkYz9vZ5udb7Hj1b73VmEHs/w=; fh=1pO/fnqlbA1DlSshLp2Kp23nBXobkeZ558bQEuNU3Z8=; b=ItNbC4GtTuOpNDGUzUCGrBtjzH+LOB567701n1B6ZpRzIdk9bHY0SimVFLJxbbB9p7 2R2cED4cqIq6KXT+YHCFviQW1UB1t1RvUqgT7B0Ga7z+zxb8vX/2dwIrx425gbOnidai h282xiWO7MIkAe73UzbVlPn7iakoJ3YttzuvHH2ega2Oqd2COPufEtoUVpIKFL6XcGGK MHT+/er+tIBvGLz3/l4zln/+sCAzRLehRinYj2BQNwDnZIaRrVkkEzpfvFIKZsvawjr9 6/k3jrDC5zf7emMMlaTF0SSsPF6LMJFXTIoKXdWPfvy7420BTFO3q/XKWCZuoR0AlOuS e9Qg==; dara=google.com 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-70557-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70557-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id t18-20020a63b252000000b005dbdb1aec55si3223323pgo.649.2024.02.18.11.51.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:51:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70557-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=sdfg.com.ar); spf=pass (google.com: domain of linux-kernel+bounces-70557-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70557-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id CE8F828174C for ; Sun, 18 Feb 2024 19:51:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 637A571B59; Sun, 18 Feb 2024 19:51:35 +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 7CF3D6F530 for ; Sun, 18 Feb 2024 19:51:31 +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=1708285893; cv=none; b=spLt8+qzkw7nU0ajhM/qnBb6H1X7wvRX8v5c9ucT1TJNdWlHLX4Jjj2fzMzuxUbuEOPL46ivHnDGu4ZwntL+Z9Xa24FK6vJ/r9LMpfbs2P0n569N5o2DZ/tHN5q0XvcOoyyimgjomdzjEYJoj0JxyutjSFsS5u3YBOr0p0pThwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708285893; c=relaxed/simple; bh=NCTX0VU3c7uspprCV+2aXLrCV3/0rWtBzeXwFk/kFIc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Bw+44OnQdJbYPwLNjvoftWN2A8Tr0jyMrkYVICd/VODm6wzcHuXJIo/xD6BMk8CmidoJHWFXXFOZzgahEgmks5J6UVi76024yc+vi9KWG3lx5kXcblv6LI51R14BezqdlrpVVx3EgNqMWR2WJz1vkAVDggV4A4k2cCrGBnQj0Rc= 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 lindsay.fibertel.com.ar by sdfg.com.ar (chasquid) with ESMTPSA tls TLS_AES_128_GCM_SHA256 (over submission, TLS-1.3, envelope from "rodrigo@sdfg.com.ar") ; Sun, 18 Feb 2024 19:51:29 +0000 From: Rodrigo Campos To: Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, Rodrigo Campos Subject: [PATCH v3 0/4] Misc fixes for strlcpy() and strlcat() Date: Sun, 18 Feb 2024 16:51:02 -0300 Message-ID: <20240218195110.1386840-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: 1791267604393332124 X-GMAIL-MSGID: 1791267604393332124 As requested by Willy and Thomas[1], here go some more fixes and tests for strlcpy() and strlcat(). The first patch just fixes the compilation when the compiler might replace some code with its strlen() implementation, which will not be found. Therefore, we just export it as that can happen also on user-code, outside of nolibc. The rest of the commits: * Fix the return code of both functions * Make sure to always null-terminate the dst buffer * Honor the size parameter as documented * Add tests for both functions All has been checked against the corresponding libbsd implementation[2]. Let me know what you think 🙂 --- Changes from v2: * Add v3 to the subject, previously I wasn't using v * Make strlcat() and strlcpy() have a shorter size when compiled * Make src and dst buffer sizes different in test and add trailing chars, so we can easily detect more bugs. [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 | 47 ++++++++++++-------- tools/testing/selftests/nolibc/nolibc-test.c | 40 +++++++++++++++++ 2 files changed, 69 insertions(+), 18 deletions(-)