From mboxrd@z Thu Jan 1 00:00:00 1970 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