public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r11-7503] libstdc++: Fix buffer overflows in tests [PR 99382]
Date: Thu,  4 Mar 2021 10:31:39 +0000 (GMT)	[thread overview]
Message-ID: <20210304103139.56FD5386F47A@sourceware.org> (raw)

https://gcc.gnu.org/g:905ce0ca30cb33cddf024b0aebf4ba0b2c86fe77

commit r11-7503-g905ce0ca30cb33cddf024b0aebf4ba0b2c86fe77
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Mar 4 10:28:38 2021 +0000

    libstdc++: Fix buffer overflows in tests [PR 99382]
    
    This seems to be a typo/thinko in the definition of the arrays used as
    storage.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/99382
            * testsuite/20_util/specialized_algorithms/uninitialized_default_n/sizes.cc:
            Make storage larger than required. Verify no write to the last
            element.
            * testsuite/20_util/specialized_algorithms/uninitialized_value_construct_n/sizes.cc:
            Likewise.

Diff:
---
 .../specialized_algorithms/uninitialized_default_n/sizes.cc        | 4 +++-
 .../uninitialized_value_construct_n/sizes.cc                       | 7 ++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_default_n/sizes.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_default_n/sizes.cc
index fbe14d41ed7..1a1aba4d5b0 100644
--- a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_default_n/sizes.cc
+++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_default_n/sizes.cc
@@ -41,10 +41,12 @@ test02()
     int operator>(void*) { return value != 0; }
   };
 
-  int i[3];
+  int i[5] = { 1, 2, 3, 4, 5 };
   Size n = {4};
   auto j = std::__uninitialized_default_n(i, n);
   VERIFY( j == (i + 4) );
+  // i[0:3] are default-initialized so have indeterminate values.
+  VERIFY( i[4] == 5 );
 }
 
 int
diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_value_construct_n/sizes.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_value_construct_n/sizes.cc
index d227de4fd80..5833f7ed6c3 100644
--- a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_value_construct_n/sizes.cc
+++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_value_construct_n/sizes.cc
@@ -42,10 +42,15 @@ test02()
     int operator>(void*) { return value != 0; }
   };
 
-  int i[3];
+  int i[5] = { 1, 2, 3, 4, 5 };
   Size n = {4};
   auto j = std::__uninitialized_default_n(i, n);
   VERIFY( j == (i + 4) );
+  VERIFY( i[0] == 0 );
+  VERIFY( i[1] == 0 );
+  VERIFY( i[2] == 0 );
+  VERIFY( i[3] == 0 );
+  VERIFY( i[4] == 5 );
 }
 
 int


                 reply	other threads:[~2021-03-04 10:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210304103139.56FD5386F47A@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@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).