From patchwork Thu Dec 21 18:59:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1879400 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=jLVreUpi; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sx09s16pNz1ydZ for ; Fri, 22 Dec 2023 06:00:16 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 976943864C5D for ; Thu, 21 Dec 2023 19:00:13 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) by sourceware.org (Postfix) with ESMTPS id ADCA33861859 for ; Thu, 21 Dec 2023 18:59:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ADCA33861859 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org ADCA33861859 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703185190; cv=none; b=CGb50Yot+RoaGW6CepVGx5Kayb7kunY3ZXDacZhyV8hhVNQzF80sqM63c/3l1pvPj8jN2r5Ual2WVwbwi4fCIFgEi0NOsryDIGH5HW6j30TIT1jtYsLj9CNfcRalH8a0B4x7ddpJshJg3gpGbgV8kElE8DyC9lA5tx54N+QJc8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703185190; c=relaxed/simple; bh=k1713LFYRlIy3qnyEHvVoeeQLL+DNZ5DFqZr/vl/KXQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=O9wQ9nF7vFKk3sCjmN0EoAD9CWQJt4MXgBz0X2qEx2Eren5AdPij71Jcqqsszq6lBIid4nOZ4WUdqfn0sl6fDANb8lWar9VxO1gGOalTcHsTAAmSEftoRuJfrbitjgCLp4S5s60mD3JF7f/DBFZaFt4Fjk9mEOKapWOE7jpNqF0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-594178b3959so777591eaf.0 for ; Thu, 21 Dec 2023 10:59:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703185188; x=1703789988; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=bVbV422tiQZ9O663979Ox6WGT4oVLRQUR/M2jQJ/+io=; b=jLVreUpiFFlLl8OxccxxoV5TaelNUfoTSmLWSkY/Im0I1JANl1PSBDwkGWnMJjUL8G DSpmcPppslIxH7aUYonB2OHTcCRgyEqoZRxkf6DOd050kxITIV1U1CUNOyU2zzaBe298 mlZF1ehdy7yBf7FXsD09Sm6fNZYTnqfrsRGA4QAP+Sm4JRQUYkGzix87uFQvzU0SBUh4 2bKJ7eveXzQhlQTm42pL9M+CJ5ShARkAXZELtPNaWoqELQRayp7wZr1O75E6faQxK2b+ AicjBS0HwX/K6n+CJXV4wDpEnY8fNiPB1Jmnz4gDu/KjsKkewHbgP0AP5paDZ9sCTu1O LUwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703185188; x=1703789988; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bVbV422tiQZ9O663979Ox6WGT4oVLRQUR/M2jQJ/+io=; b=RLPpx1ovn2eKguo7hOMAdXCsK9ZBQ8zHZSTn2vdQi+ZjhmZXdQMGqhg/qbjV/OA3kA y3UIt3XwHxW7ye0KAAobiPrDS/tmQgZhZ39YPyGUjztuPluSzsfAWEtw5Gg0ubQ24dGg uDh6oZC1mVR5tS7eP0OTJNNf+jmeD/Nnh6irMRF8G2DZCa67AfRF0WkFI02CLOhtUYIU jrC9k2VKqCscyMPmqxGNJOi5evJR6UlPOyluvi3LeG90ksRAVlyoLSeBVvP1eJboNwiy WKK1JkZcMgdPs1s2CjijHBSLOSFzfga+Crwf8EknFyVWfCbAJigOODzLLfeJWV+e9gJ8 ov3Q== X-Gm-Message-State: AOJu0YxFgZOhEJRIerPSVRfTMQ3naVNtF6CBcjh/RlAvFa7mezipystw VekNxQqAQt6ZKEnz3r4NS/eap9xkFQfcFgYznz+xONBSpXA= X-Google-Smtp-Source: AGHT+IG1N3x0rkfNBrRCW1AZ5IVorB/cdiJGiSkXm5dp4kvdUk2057cYP91xR/18CmDvDU9A3Txldw== X-Received: by 2002:a05:6359:5e8a:b0:170:f1ac:af13 with SMTP id px10-20020a0563595e8a00b00170f1acaf13mr211371rwb.23.1703185188387; Thu, 21 Dec 2023 10:59:48 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c0:8192:ecd7:d327:bea0:14dc]) by smtp.gmail.com with ESMTPSA id a9-20020a63e409000000b005cdbebd61d8sm1946165pgi.9.2023.12.21.10.59.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 10:59:47 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Siddhesh Poyarekar Subject: [PATCH 03/15] debug: Add fortify dprintf tests Date: Thu, 21 Dec 2023 15:59:17 -0300 Message-Id: <20231221185929.1307116-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221185929.1307116-1-adhemerval.zanella@linaro.org> References: <20231221185929.1307116-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Similar to other printf-like ones. Checked on aarch64, armhf, x86_64, and i686. Reviewed-by: Siddhesh Poyarekar --- debug/tst-fortify.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/debug/tst-fortify.c b/debug/tst-fortify.c index 5cd9d22feb..888eae25ad 100644 --- a/debug/tst-fortify.c +++ b/debug/tst-fortify.c @@ -59,6 +59,8 @@ static char *temp_filename; +static int temp_fd_dprintf; + static void do_prepare (int argc, char *argv[]) { @@ -76,6 +78,13 @@ do_prepare (int argc, char *argv[]) unlink (temp_filename); exit (1); } + + temp_fd_dprintf = create_temp_file ("tst-chk2.", NULL); + if (temp_fd_dprintf == -1) + { + printf ("cannot create temporary file: %m\n"); + exit (1); + } } #define PREPARE do_prepare @@ -901,6 +910,10 @@ do_test (void) || n1 != 1 || n2 != 2) FAIL (); + if (dprintf (temp_fd_dprintf, "%s%n%s%n", str2, &n1, str2, &n2) != 2 + || n1 != 1 || n2 != 2) + FAIL (); + strcpy (buf2 + 2, "%n%s%n"); /* When the format string is writable and contains %n, with -D_FORTIFY_SOURCE=2 it causes __chk_fail. */ @@ -914,6 +927,11 @@ do_test (void) FAIL (); CHK_FAIL2_END + CHK_FAIL2_START + if (dprintf (temp_fd_dprintf, buf2, str2, &n1, str2, &n1) != 2) + FAIL (); + CHK_FAIL2_END + /* But if there is no %n, even writable format string should work. */ buf2[6] = '\0'; @@ -1263,6 +1281,10 @@ do_test (void) snprintf (buf, buf_size, "%3$d\n", 1, 2, 3, 4); CHK_FAIL2_END + CHK_FAIL2_START + dprintf (temp_fd_dprintf, "%3$d\n", 1, 2, 3, 4); + CHK_FAIL2_END + int sp[2]; if (socketpair (PF_UNIX, SOCK_STREAM, 0, sp)) FAIL ();