From patchwork Wed Aug 17 17:19:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zack Weinberg X-Patchwork-Id: 660204 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sDwvg5Rvnz9t24 for ; Thu, 18 Aug 2016 03:19:43 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=fajdTLRK; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:in-reply-to:references:content-transfer-encoding; q=dns; s=default; b=UwkTqQZQ3cdIel1uMlIMqPu6RJRmSjsfHAB9bnBiwAQ pV7vg51iyD0HnwJ/VHeWNXxNsvbhehbKjIvtcIG0dIe/Mlz2k7E+CyDnotcl57nu TqJujct2/gRdrWKVUHicI7FhCKRgSv+0+0tLpk/cLbGAsWgagLgN6r5y/huhFYME = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:in-reply-to:references:content-transfer-encoding; s=default; bh=RWvuGMenX5dpWQZh6m/FzZZOAPM=; b=fajdTLRK/2yZCLy3U KtaoLarZFDM30mrUeWK6+PpOJWqUxZTCaUCQDHky+YzK5vYGAwqYR3YykDunGfyv +EMubl4+Php5hvI5Ym97op/RlNsRZdy6USoqECAytOMEcuKym1p7SBWxI8EMuY8Z j5DK0NRt1LAeWoGJja2Fn/2hEE= Received: (qmail 82791 invoked by alias); 17 Aug 2016 17:19:22 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 82666 invoked by uid 89); 17 Aug 2016 17:19:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=formerly, 1516, Hx-languages-length:3590, 3006 X-HELO: mailbackend.panix.com From: Zack Weinberg To: libc-alpha@sourceware.org Cc: fweimer@redhat.com Subject: [PATCH 1/4] Add tests for fortification of bcopy and bzero. Date: Wed, 17 Aug 2016 13:19:14 -0400 Message-Id: MIME-Version: 1.0 In-Reply-To: References: This was formerly bundled with the tests for fortification of explicit_bzero, but is unconnected and I'd like to go ahead and land it ASAP. zw * debug/tst-chk1.c: Add tests for fortification of bcopy and bzero. --- debug/tst-chk1.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c index 4f968ee..478c2fb 100644 --- a/debug/tst-chk1.c +++ b/debug/tst-chk1.c @@ -143,6 +143,11 @@ do_test (void) if (memcmp (buf, "aabcdefghi", 10)) FAIL (); + memcpy (buf, "abcdefghij", 10); + bcopy (buf, buf + 1, 9); + if (memcmp (buf, "aabcdefghi", 10)) + FAIL (); + if (mempcpy (buf + 5, "abcde", 5) != buf + 10 || memcmp (buf, "aabcdabcde", 10)) FAIL (); @@ -151,6 +156,10 @@ do_test (void) if (memcmp (buf, "aabcdabcjj", 10)) FAIL (); + bzero (buf + 8, 2); + if (memcmp (buf, "aabcdabc\0\0", 10)) + FAIL (); + strcpy (buf + 4, "EDCBA"); if (memcmp (buf, "aabcEDCBA", 10)) FAIL (); @@ -175,6 +184,11 @@ do_test (void) if (memcmp (buf, "aabcdefghi", 10)) FAIL (); + memcpy (buf, "abcdefghij", l0 + 10); + bcopy (buf, buf + 1, l0 + 9); + if (memcmp (buf, "aabcdefghi", 10)) + FAIL (); + if (mempcpy (buf + 5, "abcde", l0 + 5) != buf + 10 || memcmp (buf, "aabcdabcde", 10)) FAIL (); @@ -183,6 +197,10 @@ do_test (void) if (memcmp (buf, "aabcdabcjj", 10)) FAIL (); + bzero (buf + 8, l0 + 2); + if (memcmp (buf, "aabcdabc\0\0", 10)) + FAIL (); + strcpy (buf + 4, str1 + 5); if (memcmp (buf, "aabcEDCBA", 10)) FAIL (); @@ -214,11 +232,18 @@ do_test (void) if (memcmp (buf, "aabcEcdZY", 10)) FAIL (); + /* The following tests are supposed to succeed at all fortify + levels, even though they overflow a.buf1 into a.buf2. */ memcpy (a.buf1, "abcdefghij", l0 + 10); memmove (a.buf1 + 1, a.buf1, l0 + 9); if (memcmp (a.buf1, "aabcdefghi", 10)) FAIL (); + memcpy (a.buf1, "abcdefghij", l0 + 10); + bcopy (a.buf1, a.buf1 + 1, l0 + 9); + if (memcmp (a.buf1, "aabcdefghi", 10)) + FAIL (); + if (mempcpy (a.buf1 + 5, "abcde", l0 + 5) != a.buf1 + 10 || memcmp (a.buf1, "aabcdabcde", 10)) FAIL (); @@ -227,6 +252,10 @@ do_test (void) if (memcmp (a.buf1, "aabcdabcjj", 10)) FAIL (); + bzero (a.buf1 + 8, l0 + 2); + if (memcmp (a.buf1, "aabcdabc\0\0", 10)) + FAIL (); + #if __USE_FORTIFY_LEVEL < 2 /* The following tests are supposed to crash with -D_FORTIFY_SOURCE=2 and sufficient GCC support, as the string operations overflow @@ -284,6 +313,14 @@ do_test (void) memmove (buf + 2, buf + 1, l0 + 9); CHK_FAIL_END + CHK_FAIL_START + bcopy (buf + 1, buf + 2, 9); + CHK_FAIL_END + + CHK_FAIL_START + bcopy (buf + 1, buf + 2, l0 + 9); + CHK_FAIL_END + CHK_FAIL_START p = (char *) mempcpy (buf + 6, "abcde", 5); CHK_FAIL_END @@ -300,6 +337,14 @@ do_test (void) memset (buf + 9, 'j', l0 + 2); CHK_FAIL_END + CHK_FAIL_START + bzero (buf + 9, 2); + CHK_FAIL_END + + CHK_FAIL_START + bzero (buf + 9, l0 + 2); + CHK_FAIL_END + CHK_FAIL_START strcpy (buf + 5, str1 + 5); CHK_FAIL_END @@ -377,6 +422,14 @@ do_test (void) memmove (a.buf1 + 2, a.buf1 + 1, l0 + 9); CHK_FAIL_END + CHK_FAIL_START + bcopy (a.buf1 + 1, a.buf1 + 2, 9); + CHK_FAIL_END + + CHK_FAIL_START + bcopy (a.buf1 + 1, a.buf1 + 2, l0 + 9); + CHK_FAIL_END + CHK_FAIL_START p = (char *) mempcpy (a.buf1 + 6, "abcde", 5); CHK_FAIL_END @@ -393,6 +446,14 @@ do_test (void) memset (a.buf1 + 9, 'j', l0 + 2); CHK_FAIL_END + CHK_FAIL_START + bzero (a.buf1 + 9, 2); + CHK_FAIL_END + + CHK_FAIL_START + bzero (a.buf1 + 9, l0 + 2); + CHK_FAIL_END + # if __USE_FORTIFY_LEVEL >= 2 # define O 0 # else