From patchwork Wed Jul 8 20:20:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael M Zinsly X-Patchwork-Id: 1325454 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=CzJDMdPB; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B29fm0H5Wz9s1x for ; Thu, 9 Jul 2020 06:20:48 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8B0F4386186E; Wed, 8 Jul 2020 20:20:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B0F4386186E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1594239644; bh=IK1XahNklDQ/H2yc+MjwLBTFmKFG7Fi0AxMVkXquGxI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=CzJDMdPBNsSfgvClxsgCWYAs4TOmrf3j8krTUsme3SnYv089f3tXv3xBjfoYcyMao cv+jMWMvwA26TUTEyHXUpG5M9oETqMTdTlNGkO2CzM4tFRDmh+Op3Ln4yEXhKJfCZO QTYXRFFNqJlhdfNNDfaocB/JDD8NvTMVt3voQHeI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 2A9313858D34 for ; Wed, 8 Jul 2020 20:20:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2A9313858D34 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 068K2V9P156299; Wed, 8 Jul 2020 16:20:41 -0400 Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0b-001b2d01.pphosted.com with ESMTP id 325mp20p08-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Jul 2020 16:20:41 -0400 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 068KJUFx018627; Wed, 8 Jul 2020 20:20:40 GMT Received: from b03cxnp07029.gho.boulder.ibm.com (b03cxnp07029.gho.boulder.ibm.com [9.17.130.16]) by ppma02dal.us.ibm.com with ESMTP id 325k1ngyk5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Jul 2020 20:20:40 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 068KKdwQ59244880 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 8 Jul 2020 20:20:39 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 35073C605B; Wed, 8 Jul 2020 20:20:39 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C2D70C6057; Wed, 8 Jul 2020 20:20:38 +0000 (GMT) Received: from localhost (unknown [9.163.3.66]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 8 Jul 2020 20:20:38 +0000 (GMT) To: libc-alpha@sourceware.org Subject: [PATCH v6] string: Adds tests for test-strncasecmp and test-strncpy Date: Wed, 8 Jul 2020 17:20:09 -0300 Message-Id: <20200708202009.22055-1-rzinsly@linux.ibm.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-07-08_17:2020-07-08, 2020-07-08 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 spamscore=0 suspectscore=1 mlxscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 mlxlogscore=792 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007080117 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Raphael Moreira Zinsly via Libc-alpha From: Raphael M Zinsly Reply-To: Raphael Moreira Zinsly Cc: Raphael Moreira Zinsly , pc@us.ibm.com Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Changes since v5: string/test-strncpy.c: - Adjusted s1 and s2 placements. - Used the same pattern as test-strncasecmp. --- >8 --- Adds tests to check if strings placed at page bondaries are handled correctly by strncasecmp and strncpy similar to tests for strncmp and strnlen. --- string/test-strncasecmp.c | 44 +++++++++++++++++++++++++++++++++++++++ string/test-strncpy.c | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/string/test-strncasecmp.c b/string/test-strncasecmp.c index 6a9c27beae..628135b962 100644 --- a/string/test-strncasecmp.c +++ b/string/test-strncasecmp.c @@ -137,6 +137,49 @@ do_test (size_t align1, size_t align2, size_t n, size_t len, int max_char, do_one_test (impl, s1, s2, n, exp_result); } +static void +do_page_tests (void) +{ + char *s1, *s2; + int exp_result; + /* Assumes up to 512-bit wide read/stores. */ + const size_t maxoffset = 64; + + s1 = (char *) buf1 + (BUF1PAGES) * page_size - maxoffset; + memset (s1, 'a', maxoffset - 1); + s1[maxoffset - 1] = '\0'; + + s2 = (char *) buf2 + page_size - maxoffset; + memset (s2, 'a', maxoffset - 1); + s2[maxoffset - 1] = '\0'; + + /* At this point s1 and s2 points to distinct memory regions containing + "aa..." with size of 63 plus '\0'. Also, both strings are bounded to a + page with write/read access and the next page is protected with PROT_NONE + (meaning that any access outside of the page regions will trigger an + invalid memory access). + + The loop checks for all possible offset up to maxoffset for both + inputs with a size larger than the string (so memory access outside + the expected memory regions might trigger invalid access). */ + + for (size_t off1 = 0; off1 < maxoffset; off1++) + { + for (size_t off2 = 0; off2 < maxoffset; off2++) + { + exp_result = off1 == off2 + ? 0 + : off1 < off2 + ? 'a' + : -'a'; + + FOR_EACH_IMPL (impl, 0) + check_result (impl, s1 + off1, s2 + off2, maxoffset + 1, + exp_result); + } + } +} + static void do_random_tests (void) { @@ -334,6 +377,7 @@ test_locale (const char *locale) } do_random_tests (); + do_page_tests (); } int diff --git a/string/test-strncpy.c b/string/test-strncpy.c index c978753ad8..c8d4ad58a6 100644 --- a/string/test-strncpy.c +++ b/string/test-strncpy.c @@ -155,6 +155,41 @@ do_test (size_t align1, size_t align2, size_t len, size_t n, int max_char) do_one_test (impl, s2, s1, len, n); } +static void +do_page_tests (void) +{ + CHAR *s1, *s2; + /* Assumes up to 512-bit wide read/stores. */ + const size_t maxoffset = 64; + + /* Put s1 at the edge of buf1's last page. */ + s1 = (CHAR *) buf1 + (BUF1PAGES) * (page_size / sizeof(CHAR)) - maxoffset; + /* Put s2 almost at the edge of buf2, it needs room to put a string with + size of maxoffset + 1 at s2 + maxoffset. */ + s2 = (CHAR *) buf2 + (page_size / sizeof(CHAR)) - (maxoffset + 1) * 2; + + MEMSET (s1, 'a', maxoffset - 1); + s1[maxoffset - 1] = '\0'; + + /* Both strings are bounded to a page with write/read access and the next + page is protected with PROT_NONE (meaning that any access outside of the + page regions will trigger an invalid memory access). + + The loop copies the string s1 for all possible offset up to maxoffset + for both inputs with a size larger than s1 (so memory access outside the + expected memory regions might trigger invalid access). */ + + for (size_t off1 = 0; off1 < maxoffset; off1++) + { + for (size_t off2 = 0; off2 < maxoffset; off2++) + { + FOR_EACH_IMPL (impl, 0) + do_one_test (impl, (s2 + off2), (s1 + off1), maxoffset - off1 - 1, + maxoffset + 1); + } + } +} + static void do_random_tests (void) { @@ -317,6 +352,7 @@ test_main (void) } do_random_tests (); + do_page_tests (); return ret; }