Skip to content

Commit e0c5dc2

Browse files
committed
Fix Klocwork non null terminated string with default C++11 ABI
After switching libstdc++ from the old to the default, new C++11 ABI, Klocwork static analysis flags that assignment to std::string with a string literal may result in a non null terminated string. While it is not apparent whether this is a false-positive or not, initializing the string with the literal by default resolves the Klocwork issue. --------------------------------------------------------------------------- 182 (Local) /__w/fpga-runtime-for-opencl/fpga-runtime-for-opencl/src/acl_hal_mmd.cpp:782 NNTS.MUST (1:Critical) Analyze Buffer overflow of 'board_vendor_path._M_dataplus._M_p' due to non null terminated string 'board_vendor_path._M_dataplus._M_p' * acl_hal_mmd.cpp:773: customer_board_vendor_path is false * acl_hal_mmd.cpp:779: 'board_vendor_path._M_dataplus._M_p' may not be null-terminated after calling 'operator='. * basic_string.h:705: 'this->_M_dataplus._M_p' may not be null-terminated after calling 'assign'. * basic_string.h:1438: 'this->_M_dataplus._M_p' may not be null-terminated after calling '_M_replace'. * basic_string.tcc:429: __new_size<=this->capacity() is false * basic_string.tcc:465: 'this->_M_dataplus._M_p' may not be null-terminated after calling '_M_mutate'. * basic_string.tcc:318: __pos is true * basic_string.tcc:319: '__r' may not be null-terminated after calling '_S_copy'. * basic_string.h:348: __n==1 is false * basic_string.h:351: '__d' may not be null-terminated after calling 'copy'. * char_traits.h:365: The size parameter may be less than length of source buffer. * char_traits.h:365: '__s1' may not be null-terminated after calling '__builtin_memcpy'. * basic_string.tcc:320: __len2 is false * basic_string.tcc:320: __s&&__len2 is false * basic_string.tcc:322: __how_much is false * basic_string.tcc:327: _M_data(__r): copies '__r' into 'this->_M_dataplus._M_p' * acl_hal_mmd.cpp:783: board_vendor_path.c_str(): returns 'board_vendor_path._M_dataplus._M_p' * acl_hal_mmd.cpp:782: String 'board_vendor_path._M_dataplus._M_p' is not properly terminated and is passed as an argument to function 'printf'. Current status 'Analyze' --------------------------------------------------------------------------- 183 (Local) /__w/fpga-runtime-for-opencl/fpga-runtime-for-opencl/src/acl_hal_mmd.cpp:798 NNTS.MUST (1:Critical) Analyze Buffer overflow of 'board_vendor_path._M_dataplus._M_p' due to non null terminated string 'board_vendor_path._M_dataplus._M_p' * acl_hal_mmd.cpp:773: customer_board_vendor_path is false * acl_hal_mmd.cpp:779: 'board_vendor_path._M_dataplus._M_p' may not be null-terminated after calling 'operator='. * basic_string.h:705: 'this->_M_dataplus._M_p' may not be null-terminated after calling 'assign'. * basic_string.h:1438: 'this->_M_dataplus._M_p' may not be null-terminated after calling '_M_replace'. * basic_string.tcc:429: __new_size<=this->capacity() is false * basic_string.tcc:465: 'this->_M_dataplus._M_p' may not be null-terminated after calling '_M_mutate'. * basic_string.tcc:318: __pos is true * basic_string.tcc:319: '__r' may not be null-terminated after calling '_S_copy'. * basic_string.h:348: __n==1 is false * basic_string.h:351: '__d' may not be null-terminated after calling 'copy'. * char_traits.h:365: The size parameter may be less than length of source buffer. * char_traits.h:365: '__s1' may not be null-terminated after calling '__builtin_memcpy'. * basic_string.tcc:320: __len2 is false * basic_string.tcc:320: __s&&__len2 is false * basic_string.tcc:322: __how_much is false * basic_string.tcc:327: _M_data(__r): copies '__r' into 'this->_M_dataplus._M_p' * acl_hal_mmd.cpp:782: debug_verbosity>=1 is false * acl_hal_mmd.cpp:821: debug_verbosity>=1 is false * acl_hal_mmd.cpp:798: board_vendor_path.c_str(): returns 'board_vendor_path._M_dataplus._M_p' * acl_hal_mmd.cpp:798: String 'board_vendor_path._M_dataplus._M_p' is not properly terminated and is passed as an argument to function 'opendir'. Current status 'Analyze'
1 parent 0605379 commit e0c5dc2

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

src/acl_hal_mmd.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ cl_bool l_load_board_libraries(cl_bool load_libraries) {
763763
cl_bool l_load_board_libraries(cl_bool load_libraries) {
764764
// Keeping the old path for backward compatibility
765765
std::string board_vendor_path_old = "/opt/Intel/OpenCL_boards/";
766-
std::string board_vendor_path;
766+
std::string board_vendor_path = "/opt/Intel/OpenCL/Boards/";
767767
auto *customer_board_vendor_path = acl_getenv("ACL_BOARD_VENDOR_PATH");
768768
acl_assert_locked();
769769

@@ -774,9 +774,6 @@ cl_bool l_load_board_libraries(cl_bool load_libraries) {
774774
// append the '/' to the end of the customer_board_vendor_path
775775
// and load it to board_vendor_path
776776
board_vendor_path = customer_board_vendor_path + std::string("/");
777-
} else {
778-
// use the default path
779-
board_vendor_path = "/opt/Intel/OpenCL/Boards/";
780777
}
781778

782779
ACL_HAL_DEBUG_MSG_VERBOSE(1, "Intel(R) FPGA Board Vendor Path: %s\n",

0 commit comments

Comments
 (0)