Add patch to fix undefined behavior on realloc
Also refine the gating test to only run non-Valgrind, short-running tests. Related: rhbz#2034641 Signed-off-by: Bryan Gurney <bgurney@redhat.com>
This commit is contained in:
		
							parent
							
								
									8b08c68326
								
							
						
					
					
						commit
						1a73cbd967
					
				
							
								
								
									
										69
									
								
								0001-vector-Fix-undefined-behaviour-on-realloc.patch
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								0001-vector-Fix-undefined-behaviour-on-realloc.patch
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,69 @@ | |||||||
|  | From 41ddc88a80160050b0ac1a51cb258f8918edf9aa Mon Sep 17 00:00:00 2001 | ||||||
|  | From: "Lucas A. M. Magalhaes" <lamm@linux.ibm.com> | ||||||
|  | Date: Wed, 23 Jun 2021 15:05:50 -0300 | ||||||
|  | Subject: [PATCH] vector: Fix undefined behaviour on realloc | ||||||
|  | MIME-Version: 1.0 | ||||||
|  | Content-Type: text/plain; charset=UTF-8 | ||||||
|  | Content-Transfer-Encoding: 8bit | ||||||
|  | 
 | ||||||
|  | On tests listed bellow the reserve method is being called before any | ||||||
|  | allocation on the object therefore realloc being called without | ||||||
|  | any previous allocation. Inside realloc _data is being used with the | ||||||
|  | operator '[]', as it is nullptr at that moment it's an undefined | ||||||
|  | behaviour. | ||||||
|  | 
 | ||||||
|  | This patch simply returns a call to alloc if _data is nullptr. | ||||||
|  | 
 | ||||||
|  | This tests fails on PowerPC with Segmentation Fault because of this | ||||||
|  | issue: | ||||||
|  | segment_vector_array_expsize_assign_exceptions_oom_0_none | ||||||
|  | segment_vector_array_expsize_assign_exceptions_oom_0_memcheck | ||||||
|  | segment_vector_array_expsize_capacity_exceptions_oom_0_none | ||||||
|  | segment_vector_array_expsize_capacity_exceptions_oom_0_memcheck | ||||||
|  | segment_vector_array_expsize_modifiers_exceptions_oom_0_none | ||||||
|  | segment_vector_array_expsize_modifiers_exceptions_oom_0_memcheck | ||||||
|  | segment_vector_vector_expsize_assign_exceptions_oom_0_none | ||||||
|  | segment_vector_vector_expsize_assign_exceptions_oom_0_memcheck | ||||||
|  | segment_vector_vector_expsize_capacity_exceptions_oom_0_none | ||||||
|  | segment_vector_vector_expsize_capacity_exceptions_oom_0_memcheck | ||||||
|  | segment_vector_vector_expsize_modifiers_exceptions_oom_0_none | ||||||
|  | segment_vector_vector_expsize_modifiers_exceptions_oom_0_memcheck | ||||||
|  | segment_vector_vector_fixedsize_assign_exceptions_oom_0_none | ||||||
|  | segment_vector_vector_fixedsize_assign_exceptions_oom_0_memcheck | ||||||
|  | 
 | ||||||
|  | Signed-off-by: Lucas A. M. Magalhães lamm@linux.ibm.com | ||||||
|  | ---
 | ||||||
|  |  include/libpmemobj++/container/vector.hpp | 10 +++++++++- | ||||||
|  |  1 file changed, 9 insertions(+), 1 deletion(-) | ||||||
|  | 
 | ||||||
|  | diff --git a/include/libpmemobj++/container/vector.hpp b/include/libpmemobj++/container/vector.hpp
 | ||||||
|  | index f430ed50..9810220b 100644
 | ||||||
|  | --- a/include/libpmemobj++/container/vector.hpp
 | ||||||
|  | +++ b/include/libpmemobj++/container/vector.hpp
 | ||||||
|  | @@ -2362,7 +2362,8 @@ vector<T>::internal_insert(size_type idx, InputIt first, InputIt last)
 | ||||||
|  |   * Private helper function. Must be called during transaction. Allocates new | ||||||
|  |   * memory for capacity_new number of elements and copies or moves old elements | ||||||
|  |   * to new memory area. If the current size is greater than capacity_new, the | ||||||
|  | - * container is reduced to its first capacity_new elements.
 | ||||||
|  | + * container is reduced to its first capacity_new elements. If was never
 | ||||||
|  | + * allocated behaves as an alloc call.
 | ||||||
|  |   * | ||||||
|  |   * param[in] capacity_new new capacity. | ||||||
|  |   * | ||||||
|  | @@ -2381,6 +2382,13 @@ vector<T>::realloc(size_type capacity_new)
 | ||||||
|  |  { | ||||||
|  |  	assert(pmemobj_tx_stage() == TX_STAGE_WORK); | ||||||
|  |   | ||||||
|  | +	/*
 | ||||||
|  | +	 * If _data == nullptr this object has never allocated any memory
 | ||||||
|  | +	 * so we need to behave as alloc instead.
 | ||||||
|  | +	 */
 | ||||||
|  | +	if (_data == nullptr)
 | ||||||
|  | +		return alloc(capacity_new);
 | ||||||
|  | +
 | ||||||
|  |  	/* | ||||||
|  |  	 * XXX: future optimization: we don't have to snapshot data | ||||||
|  |  	 * which we will not overwrite | ||||||
|  | -- 
 | ||||||
|  | 2.27.0 | ||||||
|  | 
 | ||||||
| @ -4,7 +4,7 @@ | |||||||
| 
 | 
 | ||||||
| Name:		libpmemobj-cpp | Name:		libpmemobj-cpp | ||||||
| Version:	1.12 | Version:	1.12 | ||||||
| Release:	6%{?dist} | Release:	7%{?dist} | ||||||
| Summary:	C++ bindings for libpmemobj | Summary:	C++ bindings for libpmemobj | ||||||
| # Note: tests/external/libcxx is dual licensed using University of Illinois "BSD-Like" license and the MIT license. It's used only during development/testing and is NOT part of the binary RPM. | # Note: tests/external/libcxx is dual licensed using University of Illinois "BSD-Like" license and the MIT license. It's used only during development/testing and is NOT part of the binary RPM. | ||||||
| License:	BSD | License:	BSD | ||||||
| @ -12,6 +12,8 @@ URL:		http://pmem.io/pmdk/cpp_obj/ | |||||||
| 
 | 
 | ||||||
| Source0:	https://github.com/pmem/%{name}/archive/%{upstreamversion}.tar.gz#/%{name}-%{upstreamversion}.tar.gz | Source0:	https://github.com/pmem/%{name}/archive/%{upstreamversion}.tar.gz#/%{name}-%{upstreamversion}.tar.gz | ||||||
| 
 | 
 | ||||||
|  | Patch0:		0001-vector-Fix-undefined-behaviour-on-realloc.patch | ||||||
|  | 
 | ||||||
| BuildRequires:	libpmemobj-devel >= %{min_libpmemobj_ver} | BuildRequires:	libpmemobj-devel >= %{min_libpmemobj_ver} | ||||||
| BuildRequires:	cmake >= 3.3 | BuildRequires:	cmake >= 3.3 | ||||||
| BuildRequires:	glibc-devel | BuildRequires:	glibc-devel | ||||||
| @ -110,6 +112,10 @@ cd build | |||||||
| %make_install | %make_install | ||||||
| 
 | 
 | ||||||
| %changelog | %changelog | ||||||
|  | * Mon Jan 24 2022 Bryan Gurney <bgurney@redhat.com> - 1.12-7 | ||||||
|  | - Add patch to fix undefined behavior on realloc | ||||||
|  | - Related: rhbz#2034641 | ||||||
|  | 
 | ||||||
| * Mon Aug 09 2021 Mohan Boddu <mboddu@redhat.com> - 1.12-6 | * Mon Aug 09 2021 Mohan Boddu <mboddu@redhat.com> - 1.12-6 | ||||||
| - Rebuilt for IMA sigs, glibc 2.34, aarch64 flags | - Rebuilt for IMA sigs, glibc 2.34, aarch64 flags | ||||||
|   Related: rhbz#1991688 |   Related: rhbz#1991688 | ||||||
|  | |||||||
| @ -1,4 +1,5 @@ | |||||||
| #!/bin/bash | #!/bin/bash | ||||||
|  | set -e | ||||||
| 
 | 
 | ||||||
| NRCPUS=$(getconf _NPROCESSORS_ONLN) | NRCPUS=$(getconf _NPROCESSORS_ONLN) | ||||||
| patchfile="$PWD/libpmemobj-test-installed-libs.patch" | patchfile="$PWD/libpmemobj-test-installed-libs.patch" | ||||||
| @ -9,7 +10,7 @@ patch -p1 < $patchfile | |||||||
| 
 | 
 | ||||||
| mkdir build | mkdir build | ||||||
| cd build | cd build | ||||||
| cmake .. | cmake .. -DTESTS_USE_VALGRIND=OFF -DTESTS_LONG=OFF -DTESTS_USE_FORCED_PMEM=ON | ||||||
| make -j $NRCPUS | make -j $NRCPUS | ||||||
| 
 | 
 | ||||||
| ctest --output-on-failure | ctest --output-on-failure | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user