From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [185.226.149.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90A3C395D9B for ; Mon, 2 Mar 2026 10:18:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.37 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772446737; cv=none; b=Ea9Xt1U+3LCKVu40nCvgeoje+ke2Ud60mbB/0uIR3ZYOSq9zv1Xs9bih5UAcwKPZOSSqRCHVB/vlNPJB5IbuL4QnS2sc4pM4gcpx+s6lmPanvakJ+c7j5LYGmrFrjhObQ5qDV3JI8SMGBbVApdNyQ7Yzye8JKJ0EZ8ERZO9rhI4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772446737; c=relaxed/simple; bh=FDEbNZHxM5oJju2kC2dw9TTUbhlFm10AqW+2cMO05fk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LS5bgflXKRu/8KGeVIz9FZh99Nycf9ejzOwSlasdywPhnLKz51odpmNvIeMVlVW0uBACf7bK2lqo69s6vS60TO2q09zTfjp6ZnalIw72rscGLFoYthptWQ57nD1HJv1zr9YdA6lx5SvQHDaQvNg/d+SEo1pCnqOgOUTutsC9XDA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=runbox.com; dkim=pass (2048-bit key) header.d=runbox.com header.i=@runbox.com header.b=NRMms2yw; arc=none smtp.client-ip=185.226.149.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=runbox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=runbox.com header.i=@runbox.com header.b="NRMms2yw" Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1vx0MX-003858-UN; Mon, 02 Mar 2026 11:18:53 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; s=selector2; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=zmOX8vrTgM8TZEKsPS4lzpMrTwpbveCMW8pTLSdRgvY=; b=NRMms2ywnMHN8SkPVFgBmj//o8 7a6+kUfBN/QQ9dwNoWWAV/rfgTIV+Y987+AS6K7lrcpLH3Y8AFr69T4oDHN7KEjywhllb+GukkfVZ P0K4F+IwiOoUKggxH5hgzgwdKBF3HNwNpmrsSApG4uVRI3hLtOwI1efgdYDE1yAJJPP9ON5quTCCb FO4VEjxNjRlYjV6RZ0w9gwqkSmBWgo9qsrwBI0+GE5cN/L5xSMLj7Pz6xArT50An4hluTqCn4k7lS +DqXQV7XMSbz5xv6YXwadE4Bx8kGCXrs5lUl2UsKzwkB5eP7OPtEuYFuM/wWHzV02jXFVvosdwfRe bvvqyaLA==; Received: from [10.9.9.72] (helo=submission01.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vx0MX-0002yv-Kw; Mon, 02 Mar 2026 11:18:53 +0100 Received: by submission01.runbox with esmtpsa [Authenticated ID (1493616)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1vx0M9-006y7o-Dy; Mon, 02 Mar 2026 11:18:29 +0100 From: david.laight.linux@gmail.com To: Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kernel@vger.kernel.org, Cheng Li Cc: David Laight Subject: [PATCH v4 next 04/23] selftests/nolibc: check vsnprintf() output buffer before the length Date: Mon, 2 Mar 2026 10:17:56 +0000 Message-Id: <20260302101815.3043-5-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260302101815.3043-1-david.laight.linux@gmail.com> References: <20260302101815.3043-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: David Laight Check the string matches before checking the returned length. Only print the string once when it matches. Makes it a lot easier to diagnose any incorrect output. Signed-off-by: David Laight --- v4: split out from patch 3 tools/testing/selftests/nolibc/nolibc-test.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 9787e493523c..f4813764d56e 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1668,25 +1668,27 @@ static int expect_vfprintf(int llen, int c, const char *expected, const char *fm char buf[100]; va_list args; ssize_t w; - int ret; - va_start(args, fmt); /* Only allow writing 21 bytes, to test truncation */ w = vsnprintf(buf, 21, fmt, args); va_end(args); + llen += printf(" \"%s\"", buf); + if (strncmp(expected, buf, c)) { + llen += printf(" should be \"%s\"", expected); + result(llen, FAIL); + return 1; + } + if (w != c) { llen += printf(" written(%d) != %d", (int)w, c); result(llen, FAIL); return 1; } - llen += printf(" \"%s\" = \"%s\"", expected, buf); - ret = strncmp(expected, buf, c) != 0; - - result(llen, ret ? FAIL : OK); - return ret; + result(llen, OK); + return 0; } static int test_scanf(void) -- 2.39.5