From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [PATCH] PR libstdc++/89446 fix null pointer dereference in char_traits
Date: Sat, 23 Feb 2019 01:11:00 -0000 [thread overview]
Message-ID: <20190223010220.GA32714@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 268 bytes --]
PR libstdc++/89446
* include/bits/char_traits.h (__constant_char_array): Check index is
in range before dereferencing.
* testsuite/21_strings/basic_string_view/operators/char/89446.cc:
New test.
Tested x86_64-linux, committed to gcc-8-branch and gcc-7-branch.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2387 bytes --]
commit b639a9cac6e2532eb852b03df6ac40d34f1dd28c
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri Feb 22 20:33:16 2019 +0000
PR libstdc++/89446 fix null pointer dereference in char_traits
PR libstdc++/89446
* include/bits/char_traits.h (__constant_char_array): Check index is
in range before dereferencing.
* testsuite/21_strings/basic_string_view/operators/char/89446.cc:
New test.
diff --git a/libstdc++-v3/include/bits/char_traits.h b/libstdc++-v3/include/bits/char_traits.h
index 1945494d7e2..a2a883f3565 100644
--- a/libstdc++-v3/include/bits/char_traits.h
+++ b/libstdc++-v3/include/bits/char_traits.h
@@ -248,7 +248,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__constant_char_array_p(const _CharT* __a, size_t __n)
{
size_t __i = 0;
- while (__builtin_constant_p(__a[__i]) && __i < __n)
+ while (__i < __n && __builtin_constant_p(__a[__i]))
__i++;
return __i == __n;
}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/operators/char/89446.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/operators/char/89446.cc
new file mode 100644
index 00000000000..768ba63ddfe
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/operators/char/89446.cc
@@ -0,0 +1,28 @@
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17 -fexceptions -fnon-call-exceptions -O1" }
+// { dg-do run { target { powerpc*-*-linux* i?86-*-linux* x86_64-*-linux* } } }
+// { dg-require-effective-target c++17 }
+
+#include <string_view>
+
+int main()
+{
+ std::string_view s1, s2;
+ return s1 != s2;
+}
next reply other threads:[~2019-02-23 1:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-23 1:11 Jonathan Wakely [this message]
2019-02-23 1:27 ` Jakub Jelinek
2019-02-23 2:04 ` Jonathan Wakely
2019-02-23 7:17 ` Jonathan Wakely
2019-02-23 2:26 ` Jonathan Wakely
2019-02-23 14:59 ` Eric Botcazou
2019-02-24 12:02 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190223010220.GA32714@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).