public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed 2/4] libstdc++: Fix null dereference in pb_ds containers
Date: Tue, 4 May 2021 23:18:46 +0100	[thread overview]
Message-ID: <20210504221846.GM3008@redhat.com> (raw)
In-Reply-To: <YJHIB/bhVbWRUygY@redhat.com>

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

This fixes ubsan errors:

ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp:533:15: runtime error: member access within null pointer of type 'struct entry'

libstdc++-v3/ChangeLog:

	* include/ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp
	(find_key_pointer(key_const_reference, false_type))
	(find_key_pointer(key_const_reference, true_type)): Do not
	dereference null pointer.

Tested x86_64-linux. Committed to trunk.



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

commit ca871701c2822c3c4537745d4aa44a7b8f408337
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue May 4 15:46:28 2021

    libstdc++: Fix null dereference in pb_ds containers
    
    This fixes ubsan errors:
    
    ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp:533:15: runtime error: member access within null pointer of type 'struct entry'
    
    libstdc++-v3/ChangeLog:
    
            * include/ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp
            (find_key_pointer(key_const_reference, false_type))
            (find_key_pointer(key_const_reference, true_type)): Do not
            dereference null pointer.

diff --git a/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp b/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp
index aa5c94b9aed..c81bf3abfef 100644
--- a/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp
+++ b/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp
@@ -524,13 +524,16 @@ namespace __gnu_pbds
 
 	resize_base::notify_find_search_end();
 
-#ifdef _GLIBCXX_DEBUG
 	if (p_e == 0)
-	  PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key)
+	  {
+	    PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key)
+	    return 0;
+	  }
 	else
-	  PB_DS_CHECK_KEY_EXISTS(r_key)
-#endif
-	return &p_e->m_value;
+	  {
+	    PB_DS_CHECK_KEY_EXISTS(r_key)
+	    return &p_e->m_value;
+	  }
       }
 
       inline pointer
@@ -550,13 +553,16 @@ namespace __gnu_pbds
 
 	resize_base::notify_find_search_end();
 
-#ifdef _GLIBCXX_DEBUG
 	if (p_e == 0)
-	  PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key)
+	  {
+	    PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key)
+	    return 0;
+	  }
 	else
-	  PB_DS_CHECK_KEY_EXISTS(r_key)
-#endif
-	return &p_e->m_value;
+	  {
+	    PB_DS_CHECK_KEY_EXISTS(r_key)
+	    return &p_e->m_value;
+	  }
       }
 
       inline bool

  reply	other threads:[~2021-05-04 22:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-04 22:17 [committed 1/4] libstdc++ Fix undefined behaviour in testsuite Jonathan Wakely
2021-05-04 22:18 ` Jonathan Wakely [this message]
2021-05-04 22:19 ` [committed 3/4] libstdc++: Fix undefined behaviour in std::string Jonathan Wakely
2021-05-04 22:20 ` [committed 4/4] libstdc++: Fix null dereferences in std::promise 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=20210504221846.GM3008@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).