Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp789487rdb; Sun, 18 Feb 2024 11:51:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXIeWVoSmUMipXthDHmsIAbRziijXBVs8Hmo2Dg0zbSe8OTzVpGjIGe4PqpH6kyaiuAAoqYLSWK480RfxRqwYrMRyo6TCfAG+b46iDhjw== X-Google-Smtp-Source: AGHT+IGi2h4Z3odRf7gtyNZ1+8CsP3lWqRrT+GD8bwv0sAPUdg/f1p5l8/wd8NDlH/HoUd3cZug6 X-Received: by 2002:a05:6a21:3a81:b0:19e:abbf:a47d with SMTP id zv1-20020a056a213a8100b0019eabbfa47dmr10852243pzb.6.1708285900591; Sun, 18 Feb 2024 11:51:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708285900; cv=pass; d=google.com; s=arc-20160816; b=ZoZ0qM5aWXNIYMTnYMJcPcH7NiiNCyycepJZWZ9jUSGoWM2AnvzC5GzH+mSjbwMF00 CBVbObUHGcTYCYTbr8IVopYO8Jeldj2GhC3LthRVgTO8jeDSHsyl7PIi2b1s9UL01BkO j0TXHerY1iWtEJnbdsgA7V4V+BncS9lZ8S4IuYiQk9Fpyou73eF/2suViTj8M8trNk3x obl8cDlbF1N/lS87WiHqFMQ1VG6k2oQE2umu7QTCGl6QNmNnr/Zj6AB0uXh+IKTEyDVF wPgtmuKDNObo02MYSrVMekzqLaBl6NEsJGzxqEMgl8WsqwYmsF0vijbKet/4b49KsDZN VrWw== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70557-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id e7-20020a170902784700b001d71e1834a6si3192313pln.18.2024.02.18.11.51.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:51:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70557-linux.lists.archive=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-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70557-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 395D1281A20 for ; Sun, 18 Feb 2024 19:51:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5FBFD71B42; Sun, 18 Feb 2024 19:51:34 +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=20Wei=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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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(-) -- 2.43.0