Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp412797rdb; Mon, 29 Jan 2024 06:15:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IFzNDeeOJ9Mb2k03FkqH4QNsOoPWsc1CYRrc19MNAJNVoxW9AtORDrQp7zfRafRPAcCZ23n X-Received: by 2002:a17:906:234b:b0:a30:84aa:c2f5 with SMTP id m11-20020a170906234b00b00a3084aac2f5mr4341619eja.56.1706537758191; Mon, 29 Jan 2024 06:15:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706537758; cv=pass; d=google.com; s=arc-20160816; b=v/T/SMTRDvjK9+XEZHczGAg93Nxf3r06dA9GAgNcFCwWZ0OjaqP3g0CD3akgBXnk/6 p602C0Dg6/2ELpzniPnfXS8SDYGfMLEl3vubaK5joS/Iz/495YDppsAEdwSysEwXkP0b 1bnnJoa+aHTIA5BQOmBTOk5tjA6lNNOkH331qM0DkSKVQnWRGiusH92lPmlvlfqiAUmp y+41t9NsdEpTINuwUYLuHK1kqhiUUOrDYI2PeHoMnuewg1V8qKuIWKvUibIwtgaYbZFA xQ6QKm4bL5LnqZHGrlTuqo996AN0j8F3hsIG9QWllQmbfC9+3xcGEZqJknnr/1bl5nb6 NOxg== 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=5e/dGTJ7z+T+XCFJMU5fRg8FRn3HUWe9uaelPfJoLdM=; fh=1pO/fnqlbA1DlSshLp2Kp23nBXobkeZ558bQEuNU3Z8=; b=ZBNcncfhlCXAQm+KGFSRwRSL1R+qtc5w9Nlrp61INnpx77i6zO4yHfabVtFhfnPOBa P+n/9UPbzGf4jdElt5yw98xvXo7e4EE9JE1ZfJkS+CRrPRvucDHO78h3JE36fQ0FADsE KujKqiR+W2DTldwnA2+bgG+j1Jr1rmvq0nfZc4y1JTv80v+A07nLVNl6ZvTb2LLdrbDG fhv0jQkt2USxF0y8Ru+MFGI7DZOuyALp7OB+emVp6QezFnLvy75dGh15ysM4O/siKucd ZVOw4hSZ4hO2QX3eYLmW4Ij+kUNKRx/fsnDKWz/K72lmC7fSOpyLyKGqT6Ht/VV2bjON 8FnA== 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-42867-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42867-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g25-20020a1709061c9900b00a3555c32e86si2068793ejh.509.2024.01.29.06.15.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 06:15:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42867-linux.lists.archive=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-42867-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42867-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 E725E1F2169A for ; Mon, 29 Jan 2024 14:15:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9EA1265BC8; Mon, 29 Jan 2024 14:15:46 +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 A820D65BA7 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=1706537746; cv=none; b=pq5DRz2rjN3jJQbJIVtGb55oIK/k/qoNVQ4WCsJRja+DTT2rBe8SklvSa/ymrBrjBDE+TJORCUylPkna54BylaeJO+cW9n3KKr7ptjDyyuhlGOoPeVJWgBpCShBTQxmVYGisjEr5f5LSBw77Txkhgtz4mQQUaMBHIeSZPQ7wPu0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706537746; c=relaxed/simple; bh=t2kPYJ7pezKsYGsHLmpMN2up6sNljv6a0crp2CwK1j4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ny/Cha+7dUvuLSLt0ZY79w8O6gX9FQxl7vWdMKfpUH/aj0hxUxSqunVDnnq1s5JSbP7tG9nEVUjjmh4BOfy6d7xTu099Wv26Mqgh8MYksuFxH3/hW2VPR06leWWEjicw4wToeUmMtXC/s9KJiOqqLY2CdHjqFozXoJ35t+uwAO0= 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 2/4] tools/nolibc: Fix strlcat() return code and size usage Date: Mon, 29 Jan 2024 15:15:14 +0100 Message-ID: <20240129141516.198636-3-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) + strlen(dst), but dst is considered shorter if size is less than strlen(dst). While we are there, make sure to copy at most size-1 bytes and null-terminate the dst buffer. Signed-off-by: Rodrigo Campos --- tools/include/nolibc/string.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/include/nolibc/string.h b/tools/include/nolibc/string.h index ed15c22b1b2a..b2149e1342a8 100644 --- a/tools/include/nolibc/string.h +++ b/tools/include/nolibc/string.h @@ -187,23 +187,23 @@ char *strndup(const char *str, size_t maxlen) static __attribute__((unused)) size_t strlcat(char *dst, const char *src, size_t size) { - size_t len; char c; + size_t len = strlen(dst); + size_t ret = strlen(src) + (size < len? size: len); - for (len = 0; dst[len]; len++) - ; - - for (;;) { + for (;len < size;) { c = *src; - if (len < size) + if (len < size - 1) dst[len] = c; + if (len == size - 1) + dst[len] = '\0'; if (!c) break; len++; src++; } - return len; + return ret; } static __attribute__((unused)) -- 2.43.0