Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp413151rdb; Mon, 29 Jan 2024 06:16:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IE0vUKJnZDtZ/En9fQe5za+bzpnuBx50rGczdYI2SmCU8r8Fa4fuCd046a3HWOZfPhOOSvN X-Received: by 2002:a17:906:c50:b0:a34:b290:3a1c with SMTP id t16-20020a1709060c5000b00a34b2903a1cmr4420174ejf.2.1706537786416; Mon, 29 Jan 2024 06:16:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706537786; cv=pass; d=google.com; s=arc-20160816; b=SWJs1bX2+Y1y/qwdLUUNxxlErPyXTqC6Qwl5fjjBd9jlcZVKHEHxUgU2YpD8mpMEB9 HkENO3hYnAEe5iXQFRn0+EETk7Wd/AFzmjXxrfwXYawMnk4bmpwZR2pOt1ERqrBsBi6h HOWivbZkNlasYVQA95QBt3Ocssf2AEEBNG5vbML05nQIbO8G8NDHowmcWC5ARNq3hyMy j15IGkjE2sFH86gTvJVLPoNfcHe02LjRr91iyjhf16b1S2MO9aEf6CqsmVEI4sOuMVu9 poUQx35XVvnKS+RMRNUi/pRRwBQXsd8JsLzBk0VubZ4RwDcWukSu05iQcIyI2j7Qyep0 nMcw== 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:references:in-reply-to:message-id :date:subject:cc:to:from; bh=QFMdsPJoQ2X/PkrIym4NHWnjqdqIwU3qklc0sweEXf4=; fh=1pO/fnqlbA1DlSshLp2Kp23nBXobkeZ558bQEuNU3Z8=; b=PhT+N9uhAWT+v82vHSsTKg2YaXVRilC5dv4uzIqAulMN8GCSC0ze2gFriwE46JrOEE BNbGqKdLODAvSGr9gZ4tFGmVvtPn4G8CG6HLdC/hKWhtRYDx81mI4hFZoMTpQYsjJgZo WpLA3FOE0B4oh/YuEdwLu84pYqXOgx0MJJUA/3cTWW3AoGBl6sjNwBcOjaqArtGBV2n6 3M7W2+ByWEihahJEAZWOTzQmwFwAgYAmxZBylMAUl8t8O6cSu2xVTb7f54EQoqEOML+W E3K5VFJc4OwseahvKQ5kl8kTt9JRkJwP9dZbrR+erp8+keeisoVcpgeYx1csPFAKMOZP gejA== 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-42870-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42870-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 f17-20020a1709062c5100b00a316103ff0esi3602724ejh.36.2024.01.29.06.16.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 06:16:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42870-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-42870-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42870-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 D16341F212ED for ; Mon, 29 Jan 2024 14:16:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9B856664DF; 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 A819965BA4 for ; Mon, 29 Jan 2024 14:15:43 +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=1706537747; cv=none; b=sP6oWoAtIgGVBQveYJuTRiIQq4y/l9d5M71CLVcBYtBiOJfNB8/B1EG93UAUUsxMtaCXTzhSueemVNvzFBbys4M3ZfSkUr4aotKDYd+/nBf2EIvY5OLz7U/e3vIXXHuEA7hvb7UbrMEdT4H+tnEyhNnzNIoHzNx5fWxulto5444= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706537747; c=relaxed/simple; bh=jJmfIz4w556Ptcd31JHp/E5FbsAW+xG8mxPMPAJNtj8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u2/7FTuF6kEBELnYLRb+cmnwQY/vNEh2uMOqd4U+1QpYyAgSvaDZIodx+/zobhe+IZA9alRz9SFtBA6AoRkbIyF3Wstms/pPOpEqVsLus7PX7r3Wb6dpCcUqLo6zj3b5b9iu44/LdTdmqyHDFcr3cqFlr8ou2badJr+hKe6zUy0= 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:36 +0000 From: Rodrigo Campos To: Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, Rodrigo Campos Subject: [PATCH 3/4] tools/nolibc: Fix strlcpy() return code and size usage Date: Mon, 29 Jan 2024 15:15:15 +0100 Message-ID: <20240129141516.198636-4-rodrigo@sdfg.com.ar> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240129141516.198636-1-rodrigo@sdfg.com.ar> References: <20240129141516.198636-1-rodrigo@sdfg.com.ar> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The return code should always be strlen(src), and we should copy at most size-1 bytes. While we are there, make sure to null-terminate the dst buffer. Signed-off-by: Rodrigo Campos --- tools/include/nolibc/string.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/include/nolibc/string.h b/tools/include/nolibc/string.h index b2149e1342a8..e4bc0302967d 100644 --- a/tools/include/nolibc/string.h +++ b/tools/include/nolibc/string.h @@ -212,15 +212,16 @@ size_t strlcpy(char *dst, const char *src, size_t size) size_t len; char c; - for (len = 0;;) { + for (len = 0; len < size; len++) { c = src[len]; - if (len < size) + if (len < size - 1) dst[len] = c; + if (len == size - 1) + dst[len] = '\0'; if (!c) break; - len++; } - return len; + return strlen(src); } static __attribute__((unused)) -- 2.43.0