public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Fix buffer overflows in tests [PR 99382]
@ 2021-03-04 10:32 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2021-03-04 10:32 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 418 bytes --]

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.

Tested x86_64-linux. Committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2190 bytes --]

commit 905ce0ca30cb33cddf024b0aebf4ba0b2c86fe77
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Mar 4 10:28:38 2021

    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 --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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-04 10:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-04 10:32 [committed] libstdc++: Fix buffer overflows in tests [PR 99382] Jonathan Wakely

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).