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: 757027 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp1054012wrw; Thu, 21 Dec 2023 11:00:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IHHGz6Mk66piftVkIMxf2zxfeQDcG0Jh1TGHEfuLVtKHsgTd2MZfKVhu3Xz/uVKhHQXa3kI X-Received: by 2002:a25:69c5:0:b0:dbd:38c:e612 with SMTP id e188-20020a2569c5000000b00dbd038ce612mr218412ybc.84.1703185210999; Thu, 21 Dec 2023 11:00:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703185210; cv=pass; d=google.com; s=arc-20160816; b=BVmI6X8svNO3WpGZiBEVTekGf09fM6lEY7lkQ1xEnMZIFJI9cL9OjO12P6PCfBIzY/ 0AO+cwrNrUPxzL2hiq50detJ3kfMnja4rLxoiRS3s6u8DKByltq0pBOQpWYi/7dLfxKB hVm+N1bPzu70LF91774Cq3pRNjnU6DivnCTLAyRssRusn2+4U8H6dklNn+KqGb6nhtCo 3KQhcX01ToE7ovCncMvo1MQTOhwr9cLYHnkot04aY+Qo59V1Su+AkFsJoDeqrB+EGxLD KCCeDIdWWHPWKvPwMqQVo5hrfthULifoOdEjhEkBfJeAQfvlnTXl+nz10R7uQn1RLwgf EGTA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=bVbV422tiQZ9O663979Ox6WGT4oVLRQUR/M2jQJ/+io=; fh=JNN3k7BRNI1OnWdIBK9jlpNeitGd8uBm02dHI75AGcg=; b=SRrjNVKyby0jRZm/bl7nRX5uTRX19PCHr5DeGF+Pot3cj636CcjzDW3JcYvUzeyfAC 8V3L88taAsnpp556m2WbXePrkMJBgMN+peIokqWq6Dt0AJm2/xBlkRp8TbHmGYpm3muC YM4Jwqu7Kvk1Hz2Y2MLjdOIQtZNiL+NI7fLrsfzVUWS4Yq5SCadE+T1yir7DmIsJn36s BjsRfOOmirBfj95o/h2YjtGD1kuO+cY07QTSc6hTSy7+qSvBAtXQrwEJ+tYeAzhHwuyQ rbSPoIvrdTY8X/J2PfTbhzGDFIB6mem2H5mp1/Mt+/59RDCQ/6hZdZ2Q8o0mSuAXUKbZ rYlw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jLVreUpi; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b13-20020ac85bcd000000b00423a2fd5d34si2683062qtb.63.2023.12.21.11.00.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 11:00:10 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jLVreUpi; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A17FB384DEEE for ; Thu, 21 Dec 2023 19:00:10 +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-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+patch=linaro.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 ();