From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 9BF823AA9C3F; Thu, 6 May 2021 13:06:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9BF823AA9C3F MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-8365] libstdc++: Fix null dereference in pb_ds containers X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: cea2b1a52b3c5fe9f70daf460afe067e245bb1d7 X-Git-Newrev: 00ddf72a6f5cfe137a70d385ae3fc7a92f6b2a98 Message-Id: <20210506130620.9BF823AA9C3F@sourceware.org> Date: Thu, 6 May 2021 13:06:20 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 May 2021 13:06:20 -0000 https://gcc.gnu.org/g:00ddf72a6f5cfe137a70d385ae3fc7a92f6b2a98 commit r11-8365-g00ddf72a6f5cfe137a70d385ae3fc7a92f6b2a98 Author: Jonathan Wakely Date: Tue May 4 15:46:28 2021 +0100 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. (cherry picked from commit ca871701c2822c3c4537745d4aa44a7b8f408337) Diff: --- .../pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) 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