From patchwork Mon Nov 7 08:28:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Ostapenko X-Patchwork-Id: 81005 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp896858qge; Mon, 7 Nov 2016 00:29:13 -0800 (PST) X-Received: by 10.98.207.195 with SMTP id b186mr11320495pfg.40.1478507352963; Mon, 07 Nov 2016 00:29:12 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id p6si18937986pfg.145.2016.11.07.00.29.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Nov 2016 00:29:12 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-440570-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-440570-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-440570-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:cc:from:message-id:date:mime-version:in-reply-to :content-type:references; q=dns; s=default; b=RXFi4bsh0TI7ikWUBN N2wwDCuoNKPyJ9XenVlsBd7UcAztp1MRSRTnoVoL+VrL+U1bRCYEnbVQyNO11QwP lN9RHqs+7UwX6E7Jn4MYJtWCrGumw8H4xJ65LcY3c8Rhk8bpOQu/C6lbdG39p2T4 UWbpP2fASqsZyVnZHlGj/ztAA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:cc:from:message-id:date:mime-version:in-reply-to :content-type:references; s=default; bh=Srb02SEL/wBW4He0ScYxkwti fgI=; b=F5q200g8WLS2zAYo7iRw8m037JJRLXh5CsSoxACxnFqsTCTCOaovLTij W/BJas7+bStvY6Zq5+0G1QZPRyPB8dCpy94+kvbehBCzAvwdIGVIY79lq+JHyAZ5 pnOK+DGd+26BCOAnBAv4MeeO+b+gsU/3w6uaEGberidQeIuB1eo= Received: (qmail 95522 invoked by alias); 7 Nov 2016 08:28:58 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 95504 invoked by uid 89); 7 Nov 2016 08:28:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.7 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=READ, acb, bbc, bca X-HELO: mailout1.w1.samsung.com Received: from mailout1.w1.samsung.com (HELO mailout1.w1.samsung.com) (210.118.77.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 07 Nov 2016 08:28:47 +0000 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OG900116JJVKI50@mailout1.w1.samsung.com> for gcc-patches@gcc.gnu.org; Mon, 07 Nov 2016 08:28:43 +0000 (GMT) Received: from eusmges5.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20161107082843eucas1p2667fe1bb888f8b0982c2a31102f7bbda~EtpO0MPkC0047800478eucas1p2W; Mon, 7 Nov 2016 08:28:43 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges5.samsung.com (EUCPMTA) with SMTP id B6.CA.19540.A3B30285; Mon, 7 Nov 2016 08:28:42 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20161107082842eucas1p19cbcb798ace4eb86d8ea1460fb6ed8e0~EtpOBw4NX0119201192eucas1p1Z; Mon, 7 Nov 2016 08:28:42 +0000 (GMT) Received: from eusync2.samsung.com ( [203.254.199.212]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 98.9E.10494.C1B30285; Mon, 7 Nov 2016 08:28:12 +0000 (GMT) Received: from [106.109.129.18] by eusync2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OG900510JJSNK30@eusync2.samsung.com>; Mon, 07 Nov 2016 08:28:42 +0000 (GMT) Subject: [PATCH 6/7] Libsanitizer merge from upstream r285547. To: GCC Patches Cc: Jakub Jelinek , Kostya Serebryany , Yuri Gribov From: Maxim Ostapenko Message-id: <58203B38.9030607@samsung.com> Date: Mon, 07 Nov 2016 11:28:40 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-version: 1.0 In-reply-to: <582039C4.4040606@samsung.com> Content-type: multipart/mixed; boundary=------------000002040902000307080101 X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20161107082842eucas1p19cbcb798ace4eb86d8ea1460fb6ed8e0 X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?UTF-8?B?TWFrc2ltIE9zdGFwZW5rbxtTUlItU1cgVG9vbHMgTGFiGw==?= =?UTF-8?B?7IK87ISx7KCE7J6QG0VuZ2luZWVy?= X-Global-Sender: =?UTF-8?B?TWF4aW0gT3N0YXBlbmtvG1NSUi1TVyBUb29scyBMYWIbU2Ft?= =?UTF-8?B?c3VuZ8KgRWxlY3Ryb25pY3MbRW5naW5lZXI=?= X-Sender-Code: =?UTF-8?B?QzEwG0NJU0hRG0MxMEdEMDFHRDAxMDE1Nw==?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20161107082842eucas1p19cbcb798ace4eb86d8ea1460fb6ed8e0 X-RootMTR: 20161107082842eucas1p19cbcb798ace4eb86d8ea1460fb6ed8e0 References: <582039C4.4040606@samsung.com> X-IsSubscribed: yes This patch just adds several tests backported from upstream. >From b4677ed64e7aee1af7772750e0b18ed8271f4757 Mon Sep 17 00:00:00 2001 From: Maxim Ostapenko Date: Tue, 1 Nov 2016 16:52:13 +0300 Subject: [PATCH 6/7] Backport several testcases for ASan from upstream. gcc/ * asan.h (asan_intercepted_p): Handle BUILT_IN_STRCSPN, BUILT_IN_STRPBRK, BUILT_IN_STRSPN and BUILT_IN_STRSTR. gcc/testsuite/ * c-c++-common/asan/default_options.h: New file. * c-c++-common/asan/strcasestr-1.c: New test. * c-c++-common/asan/strcasestr-2.c: Likewise. * c-c++-common/asan/strcspn-1.c: Likewise. * c-c++-common/asan/strcspn-2.c: Likewise. * c-c++-common/asan/strpbrk-1.c: Likewise. * c-c++-common/asan/strpbrk-2.c: Likewise. * c-c++-common/asan/strspn-1.c: Likewise. * c-c++-common/asan/strspn-2.c: Likewise. * c-c++-common/asan/strstr-1.c: Likewise. * c-c++-common/asan/strstr-2.c: Likewise. * c-c++-common/asan/halt_on_error_suppress_equal_pcs-1.c: Likewise. --- gcc/ChangeLog | 5 +++ gcc/asan.h | 4 +++ gcc/testsuite/ChangeLog | 15 +++++++++ gcc/testsuite/c-c++-common/asan/default_options.h | 9 +++++ .../asan/halt_on_error_suppress_equal_pcs-1.c | 38 ++++++++++++++++++++++ gcc/testsuite/c-c++-common/asan/strcasestr-1.c | 32 ++++++++++++++++++ gcc/testsuite/c-c++-common/asan/strcasestr-2.c | 32 ++++++++++++++++++ gcc/testsuite/c-c++-common/asan/strcspn-1.c | 31 ++++++++++++++++++ gcc/testsuite/c-c++-common/asan/strcspn-2.c | 31 ++++++++++++++++++ gcc/testsuite/c-c++-common/asan/strpbrk-1.c | 31 ++++++++++++++++++ gcc/testsuite/c-c++-common/asan/strpbrk-2.c | 31 ++++++++++++++++++ gcc/testsuite/c-c++-common/asan/strspn-1.c | 31 ++++++++++++++++++ gcc/testsuite/c-c++-common/asan/strspn-2.c | 31 ++++++++++++++++++ gcc/testsuite/c-c++-common/asan/strstr-1.c | 31 ++++++++++++++++++ gcc/testsuite/c-c++-common/asan/strstr-2.c | 31 ++++++++++++++++++ 15 files changed, 383 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/asan/default_options.h create mode 100644 gcc/testsuite/c-c++-common/asan/halt_on_error_suppress_equal_pcs-1.c create mode 100644 gcc/testsuite/c-c++-common/asan/strcasestr-1.c create mode 100644 gcc/testsuite/c-c++-common/asan/strcasestr-2.c create mode 100644 gcc/testsuite/c-c++-common/asan/strcspn-1.c create mode 100644 gcc/testsuite/c-c++-common/asan/strcspn-2.c create mode 100644 gcc/testsuite/c-c++-common/asan/strpbrk-1.c create mode 100644 gcc/testsuite/c-c++-common/asan/strpbrk-2.c create mode 100644 gcc/testsuite/c-c++-common/asan/strspn-1.c create mode 100644 gcc/testsuite/c-c++-common/asan/strspn-2.c create mode 100644 gcc/testsuite/c-c++-common/asan/strstr-1.c create mode 100644 gcc/testsuite/c-c++-common/asan/strstr-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 943e21c..1da0ef9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,10 @@ 2016-11-07 Maxim Ostapenko + * asan.h (asan_intercepted_p): Handle BUILT_IN_STRCSPN, + BUILT_IN_STRPBRK, BUILT_IN_STRSPN and BUILT_IN_STRSTR. + +2016-11-07 Maxim Ostapenko + * asan.h (ASAN_STACK_MAGIC_PARTIAL): Remove. * asan.c (ASAN_STACK_MAGIC_PARTIAL): Replace with ASAN_STACK_MAGIC_MIDDLE. diff --git a/gcc/asan.h b/gcc/asan.h index a259b1a..b96395b 100644 --- a/gcc/asan.h +++ b/gcc/asan.h @@ -102,6 +102,10 @@ asan_intercepted_p (enum built_in_function fcode) || fcode == BUILT_IN_STRNCASECMP || fcode == BUILT_IN_STRNCAT || fcode == BUILT_IN_STRNCMP + || fcode == BUILT_IN_STRCSPN + || fcode == BUILT_IN_STRPBRK + || fcode == BUILT_IN_STRSPN + || fcode == BUILT_IN_STRSTR || fcode == BUILT_IN_STRNCPY; } #endif /* TREE_ASAN */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 49fab6e..afa77a8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,20 @@ 2016-11-07 Maxim Ostapenko + * c-c++-common/asan/default_options.h: New file. + * c-c++-common/asan/strcasestr-1.c: New test. + * c-c++-common/asan/strcasestr-2.c: Likewise. + * c-c++-common/asan/strcspn-1.c: Likewise. + * c-c++-common/asan/strcspn-2.c: Likewise. + * c-c++-common/asan/strpbrk-1.c: Likewise. + * c-c++-common/asan/strpbrk-2.c: Likewise. + * c-c++-common/asan/strspn-1.c: Likewise. + * c-c++-common/asan/strspn-2.c: Likewise. + * c-c++-common/asan/strstr-1.c: Likewise. + * c-c++-common/asan/strstr-2.c: Likewise. + * c-c++-common/asan/halt_on_error_suppress_equal_pcs-1.c: Likewise. + +2016-11-07 Maxim Ostapenko + * c-c++-common/asan/null-deref-1.c: Adjust testcase. 2016-10-30 Bill Schmidt diff --git a/gcc/testsuite/c-c++-common/asan/default_options.h b/gcc/testsuite/c-c++-common/asan/default_options.h new file mode 100644 index 0000000..1e5c486 --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/default_options.h @@ -0,0 +1,9 @@ +#ifdef __cplusplus +extern "C" +#endif +const char * +__asan_default_options () +{ + /* The asan_default_options string should be defined in testcase. */ + return asan_default_options; +} diff --git a/gcc/testsuite/c-c++-common/asan/halt_on_error_suppress_equal_pcs-1.c b/gcc/testsuite/c-c++-common/asan/halt_on_error_suppress_equal_pcs-1.c new file mode 100644 index 0000000..df44a04 --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/halt_on_error_suppress_equal_pcs-1.c @@ -0,0 +1,38 @@ +/* Test suppress_equal_pcs in recovery mode. */ +/* { dg-do run } */ +/* { dg-options "-fsanitize-recover=address" } */ + +static const char asan_default_options[] = "halt_on_error=false:suppress_equal_pcs=true"; +#include "default_options.h" + +#define ACCESS_ARRAY_FIVE_ELEMENTS(array, i) \ + array[i] = i; \ + array[i + 1] = i + 1; \ + array[i + 2] = i + 2; \ + array[i + 3] = i + 3; \ + array[i + 4] = i + 4; + +volatile int ten = 10; +unsigned kNumIterations = 10; + +int +main (int argc, char **argv) +{ + char a[10]; + char b[10]; + + for (int i = 0; i < kNumIterations; ++i) + { + volatile int res = a[ten + i]; + a[i + ten] = res + 3; + res = a[ten + i]; + } + return 0; +} + +/* { dg-output "\[^\n\r]*READ of size 1 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r).*" } */ +/* { dg-output "\[^\n\r]*WRITE of size 1 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r).*" } */ +/* { dg-output "\[^\n\r]*READ of size 1 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r).*" } */ +/* { dg-prune-output "\[^\n\r]*READ of size 1 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r).*" } */ +/* { dg-prune-output "\[^\n\r]*WRITE of size 1 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r).*" } */ +/* { dg-prune-output "\[^\n\r]*READ of size 1 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r).*" } */ diff --git a/gcc/testsuite/c-c++-common/asan/strcasestr-1.c b/gcc/testsuite/c-c++-common/asan/strcasestr-1.c new file mode 100644 index 0000000..a3e58df --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/strcasestr-1.c @@ -0,0 +1,32 @@ +/* { dg-do run } */ +/* { dg-shouldfail "asan" } */ + +#include +#include + +static const char asan_default_options[] = "strict_string_checks=true"; +#include "default_options.h" + +#ifndef __cplusplus +#define _GNU_SOURCE +#else +extern "C" +#endif +char *strcasestr (const char *haystack, const char *needle); + +int +main (int argc, char **argv) +{ + char *r = 0; + char s2[] = "c"; + char s1[4] = "abC"; + __asan_poison_memory_region ((char *) &s1[2], 2); + r = strcasestr (s1, s2); + assert (r == s1 + 2); + return 0; +} + +/* { dg-output "READ of size 4 at .* thread T0.*" } */ +/* { dg-output ".*(main)?.*strcasestr-1.(c:24)?.*" } */ +/* { dg-output "is located in stack of thread T0 at offset.*" } */ +/* { dg-output "\[^\n\r]*Address 0x\[0-9a-f\]+ is located in stack of thread T0.*(\n|\r\n|\r)" */ diff --git a/gcc/testsuite/c-c++-common/asan/strcasestr-2.c b/gcc/testsuite/c-c++-common/asan/strcasestr-2.c new file mode 100644 index 0000000..f21d162 --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/strcasestr-2.c @@ -0,0 +1,32 @@ +/* { dg-do run } */ +/* { dg-shouldfail "asan" } */ + +#include +#include + +static const char asan_default_options[] = "strict_string_checks=true"; +#include "default_options.h" + +#ifndef __cplusplus +#define _GNU_SOURCE +#else +extern "C" +#endif +char *strcasestr (const char *haystack, const char *needle); + +int +main (int argc, char **argv) +{ + char *r = 0; + char s1[] = "ab"; + char s2[4] = "cba"; + __asan_poison_memory_region ((char *) &s2[2], 2); + r = strcasestr (s1, s2); + assert (r == 0); + return 0; +} + +/* { dg-output "READ of size 4 at .* thread T0.*" } */ +/* { dg-output ".*(main)?.*strcasestr-2.(c:24)?.*" } */ +/* { dg-output "is located in stack of thread T0 at offset.*" } */ +/* { dg-output "\[^\n\r]*Address 0x\[0-9a-f\]+ is located in stack of thread T0.*(\n|\r\n|\r)" */ diff --git a/gcc/testsuite/c-c++-common/asan/strcspn-1.c b/gcc/testsuite/c-c++-common/asan/strcspn-1.c new file mode 100644 index 0000000..8a95bac --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/strcspn-1.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-shouldfail "asan" } */ + +#include +#include + +static const char asan_default_options[] = "strict_string_checks=true"; +#include "default_options.h" + +#ifdef __cplusplus +extern "C" +#endif +__SIZE_TYPE__ +strcspn (const char *s, const char *reject); + +int +main (int argc, char **argv) +{ + __SIZE_TYPE__ r; + char s2[] = "ab"; + char s1[4] = "caB"; + __asan_poison_memory_region ((char *) &s1[2], 2); + r = strcspn (s1, s2); + assert (r == 1); + return 0; +} + +/* { dg-output "READ of size 4 at .* thread T0.*" } */ +/* { dg-output ".*(main)?.*strcspn-1.(c:23)?.*" } */ +/* { dg-output "is located in stack of thread T0 at offset.*" } */ +/* { dg-output "\[^\n\r]*Address 0x\[0-9a-f\]+ is located in stack of thread T0.*(\n|\r\n|\r)" */ diff --git a/gcc/testsuite/c-c++-common/asan/strcspn-2.c b/gcc/testsuite/c-c++-common/asan/strcspn-2.c new file mode 100644 index 0000000..d605a41 --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/strcspn-2.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-shouldfail "asan" } */ + +#include +#include + +static const char asan_default_options[] = "strict_string_checks=true"; +#include "default_options.h" + +#ifdef __cplusplus +extern "C" +#endif +__SIZE_TYPE__ +strcspn (const char *s, const char *reject); + +int +main (int argc, char **argv) +{ + __SIZE_TYPE__ r; + char s1[] = "ab"; + char s2[4] = "abc"; + __asan_poison_memory_region ((char *) &s2[2], 2); + r = strcspn (s1, s2); + assert (r == 0); + return 0; +} + +/* { dg-output "READ of size 4 at .* thread T0.*" } */ +/* { dg-output ".*(main)?.*strcspn-2.(c:23)?.*" } */ +/* { dg-output "is located in stack of thread T0 at offset.*" } */ +/* { dg-output "\[^\n\r]*Address 0x\[0-9a-f\]+ is located in stack of thread T0.*(\n|\r\n|\r)" */ diff --git a/gcc/testsuite/c-c++-common/asan/strpbrk-1.c b/gcc/testsuite/c-c++-common/asan/strpbrk-1.c new file mode 100644 index 0000000..f4c2590 --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/strpbrk-1.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-shouldfail "asan" } */ + +#include +#include + +static const char asan_default_options[] = "strict_string_checks=true"; +#include "default_options.h" + +#ifdef __cplusplus +extern "C" +#endif +char * +strpbrk (const char *s, const char *accept); + +int +main (int argc, char **argv) +{ + char *r; + char s2[] = "ab"; + char s1[4] = "cab"; + __asan_poison_memory_region ((char *) &s1[2], 2); + r = strpbrk (s1, s2); + assert (r == s1 + 1); + return 0; +} + +/* { dg-output "READ of size 4 at .* thread T0.*" } */ +/* { dg-output ".*(main)?.*strpbrk-1.(c:23)?.*" } */ +/* { dg-output "is located in stack of thread T0 at offset.*" } */ +/* { dg-output "\[^\n\r]*Address 0x\[0-9a-f\]+ is located in stack of thread T0.*(\n|\r\n|\r)" */ diff --git a/gcc/testsuite/c-c++-common/asan/strpbrk-2.c b/gcc/testsuite/c-c++-common/asan/strpbrk-2.c new file mode 100644 index 0000000..4558694 --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/strpbrk-2.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-shouldfail "asan" } */ + +#include +#include + +static const char asan_default_options[] = "strict_string_checks=true"; +#include "default_options.h" + +#ifdef __cplusplus +extern "C" +#endif +char * +strpbrk (const char *s, const char *accept); + +int +main (int argc, char **argv) +{ + char *r; + char s1[] = "c"; + char s2[4] = "bca"; + __asan_poison_memory_region ((char *) &s2[2], 2); + r = strpbrk (s1, s2); + assert (r == s1); + return 0; +} + +/* { dg-output "READ of size 4 at .* thread T0.*" } */ +/* { dg-output ".*(main)?.*strpbrk-2.(c:23)?.*" } */ +/* { dg-output "is located in stack of thread T0 at offset.*" } */ +/* { dg-output "\[^\n\r]*Address 0x\[0-9a-f\]+ is located in stack of thread T0.*(\n|\r\n|\r)" */ diff --git a/gcc/testsuite/c-c++-common/asan/strspn-1.c b/gcc/testsuite/c-c++-common/asan/strspn-1.c new file mode 100644 index 0000000..63d96ba --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/strspn-1.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-shouldfail "asan" } */ + +#include +#include + +static const char asan_default_options[] = "strict_string_checks=true"; +#include "default_options.h" + +#ifdef __cplusplus +extern "C" +#endif +__SIZE_TYPE__ +strspn (const char *s, const char *reject); + +int +main (int argc, char **argv) +{ + __SIZE_TYPE__ r; + char s2[] = "ab"; + char s1[4] = "acb"; + __asan_poison_memory_region ((char *) &s1[2], 2); + r = strspn (s1, s2); + assert (r == 1); + return 0; +} + +/* { dg-output "READ of size 4 at .* thread T0.*" } */ +/* { dg-output ".*(main)?.*strspn-1.(c:23)?.*" } */ +/* { dg-output "is located in stack of thread T0 at offset.*" } */ +/* { dg-output "\[^\n\r]*Address 0x\[0-9a-f\]+ is located in stack of thread T0.*(\n|\r\n|\r)" */ diff --git a/gcc/testsuite/c-c++-common/asan/strspn-2.c b/gcc/testsuite/c-c++-common/asan/strspn-2.c new file mode 100644 index 0000000..ac7a742 --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/strspn-2.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-shouldfail "asan" } */ + +#include +#include + +static const char asan_default_options[] = "strict_string_checks=true"; +#include "default_options.h" + +#ifdef __cplusplus +extern "C" +#endif +__SIZE_TYPE__ +strspn (const char *s, const char *reject); + +int +main (int argc, char **argv) +{ + size_t r; + char s1[] = "bbc"; + char s2[5] = "abcd"; + __asan_poison_memory_region ((char *) &s2[3], 2); + r = strspn (s1, s2); + assert (r >= 2); + return 0; +} + +/* { dg-output "READ of size 5 at .* thread T0.*" } */ +/* { dg-output ".*(main)?.*strspn-2.(c:23)?.*" } */ +/* { dg-output "is located in stack of thread T0 at offset.*" } */ +/* { dg-output "\[^\n\r]*Address 0x\[0-9a-f\]+ is located in stack of thread T0.*(\n|\r\n|\r)" */ diff --git a/gcc/testsuite/c-c++-common/asan/strstr-1.c b/gcc/testsuite/c-c++-common/asan/strstr-1.c new file mode 100644 index 0000000..2c59e53 --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/strstr-1.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-shouldfail "asan" } */ + +#include +#include + +static const char asan_default_options[] = "strict_string_checks=true"; +#include "default_options.h" + +#ifdef __cplusplus +extern "C" +#endif +char * +strstr (const char *haystack, const char *needle); + +int +main (int argc, char **argv) +{ + char *r = 0; + char s2[] = "c"; + char s1[4] = "acb"; + __asan_poison_memory_region ((char *) &s1[2], 2); + r = strstr (s1, s2); + assert (r == s1 + 1); + return 0; +} + +/* { dg-output "READ of size 4 at .* thread T0.*" } */ +/* { dg-output ".*(main)?.*strstr-1.(c:23)?.*" } */ +/* { dg-output "is located in stack of thread T0 at offset.*" } */ +/* { dg-output "\[^\n\r]*Address 0x\[0-9a-f\]+ is located in stack of thread T0.*(\n|\r\n|\r)" */ diff --git a/gcc/testsuite/c-c++-common/asan/strstr-2.c b/gcc/testsuite/c-c++-common/asan/strstr-2.c new file mode 100644 index 0000000..785293c --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/strstr-2.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-shouldfail "asan" } */ + +#include +#include + +static const char asan_default_options[] = "strict_string_checks=true"; +#include "default_options.h" + +#ifdef __cplusplus +extern "C" +#endif +char * +strstr (const char *haystack, const char *needle); + +int +main (int argc, char **argv) +{ + char *r = 0; + char s1[] = "ab"; + char s2[4] = "cab"; + __asan_poison_memory_region ((char *) &s2[2], 2); + r = strstr (s1, s2); + assert (r == 0); + return 0; +} + +/* { dg-output "READ of size 4 at .* thread T0.*" } */ +/* { dg-output ".*(main)?.*strstr-2.(c:23)?.*" } */ +/* { dg-output "is located in stack of thread T0 at offset.*" } */ +/* { dg-output "\[^\n\r]*Address 0x\[0-9a-f\]+ is located in stack of thread T0.*(\n|\r\n|\r)" */ -- 1.9.1