From 735eba9474785e9a9e05f665d8975022619026a7 Mon Sep 17 00:00:00 2001 From: Karol Babioch Date: Wed, 28 Feb 2018 17:37:58 +0100 Subject: [PATCH 01/12] Add basic sanitizer support to CMake --- .gitmodules | 3 +++ CMakeLists.txt | 5 +++++ externals/sanitizers-cmake | 1 + 3 files changed, 9 insertions(+) create mode 100644 .gitmodules create mode 160000 externals/sanitizers-cmake diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..b49debd1 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "externals/sanitizers-cmake"] + path = externals/sanitizers-cmake + url = git://github.com/arsenm/sanitizers-cmake.git diff --git a/CMakeLists.txt b/CMakeLists.txt index cb545666..402501fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,7 @@ set(OPENJPEG_LIBRARY_PROPERTIES # Path to additional CMake modules set(CMAKE_MODULE_PATH ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake + ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/externals/sanitizers-cmake/cmake ${CMAKE_MODULE_PATH}) # -------------------------------------------------------------------------- @@ -243,6 +244,10 @@ check_symbol_exists(posix_memalign stdlib.h OPJ_HAVE_POSIX_MEMALIGN) unset(CMAKE_REQUIRED_DEFINITIONS) # memalign (obsolete) check_symbol_exists(memalign malloc.h OPJ_HAVE_MEMALIGN) + +# Make sure there is Sanitizer support in CMake +find_package(Sanitizers) + #----------------------------------------------------------------------------- # Build Library if(BUILD_JPIP_SERVER) diff --git a/externals/sanitizers-cmake b/externals/sanitizers-cmake new file mode 160000 index 00000000..6947cff3 --- /dev/null +++ b/externals/sanitizers-cmake @@ -0,0 +1 @@ +Subproject commit 6947cff3a9c9305eb9c16135dd81da3feb4bf87f From c08cc839e94f9589346a1c05c0940ba1d6dcf8a8 Mon Sep 17 00:00:00 2001 From: Karol Babioch Date: Wed, 28 Feb 2018 17:38:22 +0100 Subject: [PATCH 02/12] Add sanitizer support for jp2 executables --- src/bin/jp2/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/jp2/CMakeLists.txt b/src/bin/jp2/CMakeLists.txt index 4d4bd952..18c1ece3 100644 --- a/src/bin/jp2/CMakeLists.txt +++ b/src/bin/jp2/CMakeLists.txt @@ -44,6 +44,7 @@ endif() # Loop over all executables: foreach(exe opj_decompress opj_compress opj_dump) add_executable(${exe} ${exe}.c ${common_SRCS}) + add_sanitizers(${exe}) if(NOT ${CMAKE_VERSION} VERSION_LESS "2.8.12") target_compile_options(${exe} PRIVATE ${OPENJP2_COMPILE_OPTIONS}) endif() From 9dbe549c5d67826e6321a6b51b684ab7a24aaafe Mon Sep 17 00:00:00 2001 From: Karol Babioch Date: Wed, 28 Feb 2018 17:39:01 +0100 Subject: [PATCH 03/12] Add sanitizer support for jp3d executables --- src/bin/jp3d/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/jp3d/CMakeLists.txt b/src/bin/jp3d/CMakeLists.txt index 3cac1a8f..1b316164 100644 --- a/src/bin/jp3d/CMakeLists.txt +++ b/src/bin/jp3d/CMakeLists.txt @@ -28,6 +28,7 @@ endif() # Loop over all executables: foreach(exe opj_jp3d_compress opj_jp3d_decompress) add_executable(${exe} ${exe}.c ${common_SRCS}) + add_sanitizers(${exe}) target_link_libraries(${exe} openjp3d) # On unix you need to link to the math library: if(UNIX) From 4acb261b935079a9ed650990d49f0b93a7170ed1 Mon Sep 17 00:00:00 2001 From: Karol Babioch Date: Wed, 28 Feb 2018 17:40:12 +0100 Subject: [PATCH 04/12] Add sanitizer support for jpip executables --- src/bin/jpip/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/bin/jpip/CMakeLists.txt b/src/bin/jpip/CMakeLists.txt index 301d885b..d3bc8d8b 100644 --- a/src/bin/jpip/CMakeLists.txt +++ b/src/bin/jpip/CMakeLists.txt @@ -10,6 +10,7 @@ include_directories( # Tool to embed metadata into JP2 file add_executable(opj_jpip_addxml opj_jpip_addxml.c) +add_sanitizers(opj_jpip_addxml) # Install exe install(TARGETS opj_jpip_addxml EXPORT OpenJPEGTargets @@ -23,6 +24,7 @@ if(BUILD_JPIP_SERVER) # Build executable add_executable(opj_server ${OPJ_SERVER_SRCS}) + add_sanitizers(opj_server) target_link_libraries(opj_server ${FCGI_LIBRARIES} openjpip_server) set_property( TARGET opj_server @@ -49,6 +51,7 @@ set(EXES ) foreach(exe ${EXES}) add_executable(${exe} ${exe}.c) +add_sanitizers(${exe}) target_link_libraries(${exe} openjpip) install(TARGETS ${exe} EXPORT OpenJPEGTargets From 9d263c9b08ac7a855c8135d12bf9c4513a09fb36 Mon Sep 17 00:00:00 2001 From: Karol Babioch Date: Wed, 28 Feb 2018 17:40:30 +0100 Subject: [PATCH 05/12] Add sanitizer support for jpwl executables --- src/bin/jpwl/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/jpwl/CMakeLists.txt b/src/bin/jpwl/CMakeLists.txt index 5df225de..baaa27df 100644 --- a/src/bin/jpwl/CMakeLists.txt +++ b/src/bin/jpwl/CMakeLists.txt @@ -37,6 +37,7 @@ foreach(exe decompress compress) ${jpwl_exe}.c ${common_SRCS} ) + add_sanitizers(${jpwl_exe}) set_property( TARGET ${jpwl_exe} APPEND PROPERTY COMPILE_DEFINITIONS USE_JPWL From 24360bd84b31de9448beddf1410510aed94b6b6f Mon Sep 17 00:00:00 2001 From: Karol Babioch Date: Wed, 28 Feb 2018 17:40:53 +0100 Subject: [PATCH 06/12] Add sanitizer support for mj2 executables --- src/bin/mj2/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/mj2/CMakeLists.txt b/src/bin/mj2/CMakeLists.txt index 5d3e288b..1901f494 100644 --- a/src/bin/mj2/CMakeLists.txt +++ b/src/bin/mj2/CMakeLists.txt @@ -32,6 +32,7 @@ foreach(exe ${MJ2_SRCS} ${OPENJPEG_SOURCE_DIR}/src/bin/common/color.c ) + add_sanitizers(${exe}) set_property( TARGET ${exe} APPEND PROPERTY COMPILE_DEFINITIONS USE_MJ2 From 1e927e2cf0bae1d0d2d86d289b7aae61c277d02d Mon Sep 17 00:00:00 2001 From: Karol Babioch Date: Wed, 28 Feb 2018 17:41:31 +0100 Subject: [PATCH 07/12] Add sanitizer support for wx executables --- src/bin/wx/OPJViewer/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/wx/OPJViewer/CMakeLists.txt b/src/bin/wx/OPJViewer/CMakeLists.txt index 66cf01d2..53f007c0 100644 --- a/src/bin/wx/OPJViewer/CMakeLists.txt +++ b/src/bin/wx/OPJViewer/CMakeLists.txt @@ -26,4 +26,5 @@ set(OPJV_SRCS ${OPENJPEG_SOURCE_DIR}/src/bin/jp2/index.c ) add_executable(opjviewer ${OPJV_SRCS}) +add_sanitizers(opjviewer) target_link_libraries(opjviewer ${wxWidgets_LIBRARIES} openjpeg) From 144e548e9ebd73a8af282b5eee4251b6fb039c17 Mon Sep 17 00:00:00 2001 From: Karol Babioch Date: Wed, 28 Feb 2018 17:41:57 +0100 Subject: [PATCH 08/12] Add sanitizer support for openjp2 library --- src/lib/openjp2/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/openjp2/CMakeLists.txt b/src/lib/openjp2/CMakeLists.txt index b2714858..a8756889 100644 --- a/src/lib/openjp2/CMakeLists.txt +++ b/src/lib/openjp2/CMakeLists.txt @@ -94,11 +94,14 @@ else() if(BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS) # Builds both static and dynamic libs add_library(${OPENJPEG_LIBRARY_NAME} SHARED ${OPENJPEG_SRCS}) + add_sanitizers(${OPENJPEG_LIBRARY_NAME}) add_library(openjp2_static STATIC ${OPENJPEG_SRCS}) + add_sanitizers(openjp2_static) set_target_properties(openjp2_static PROPERTIES OUTPUT_NAME ${OPENJPEG_LIBRARY_NAME}) set(INSTALL_LIBS ${OPENJPEG_LIBRARY_NAME} openjp2_static) else() add_library(${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_SRCS}) + add_sanitizers(${OPENJPEG_LIBRARY_NAME}) set(INSTALL_LIBS ${OPENJPEG_LIBRARY_NAME}) endif() endif() @@ -135,6 +138,7 @@ if(BUILD_LUTS_GENERATOR) # internal utility to generate t1_luts.h (part of the jp2 lib) # no need to install: add_executable(t1_generate_luts t1_generate_luts.c) + add_sanitizers(t1_generate_luts) if(UNIX) target_link_libraries(t1_generate_luts m) endif() From 8753f77eb25151a39db717b08446a1a8d9eeb47c Mon Sep 17 00:00:00 2001 From: Karol Babioch Date: Wed, 28 Feb 2018 17:42:55 +0100 Subject: [PATCH 09/12] Add sanitizer support for openjp3d library --- src/lib/openjp3d/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/openjp3d/CMakeLists.txt b/src/lib/openjp3d/CMakeLists.txt index b0469af1..14fece57 100644 --- a/src/lib/openjp3d/CMakeLists.txt +++ b/src/lib/openjp3d/CMakeLists.txt @@ -23,6 +23,7 @@ endif() # build jp3d lib: add_library(${OPENJP3D_LIBRARY_NAME} ${OPENJP3D_SRCS}) +add_sanitizers(${OPENJP3D_LIBRARY_NAME}) if(UNIX) target_link_libraries(${OPENJP3D_LIBRARY_NAME} m) endif() From 97cc0941ad04292d3e99c881d301186f7519d54b Mon Sep 17 00:00:00 2001 From: Karol Babioch Date: Wed, 28 Feb 2018 17:44:09 +0100 Subject: [PATCH 10/12] Add sanitizer support for openjpip library --- src/lib/openjpip/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/openjpip/CMakeLists.txt b/src/lib/openjpip/CMakeLists.txt index b3cb8ce8..e49bc7ed 100644 --- a/src/lib/openjpip/CMakeLists.txt +++ b/src/lib/openjpip/CMakeLists.txt @@ -60,6 +60,7 @@ if(WIN32) endif() endif() add_library(openjpip ${OPENJPIP_SRCS} ${LOCAL_SRCS}) +add_sanitizers(openjpip) set_target_properties(openjpip PROPERTIES ${OPENJPEG_LIBRARY_PROPERTIES}) if(NOT ${CMAKE_VERSION} VERSION_LESS "2.8.12") @@ -81,6 +82,7 @@ install(TARGETS openjpip if(BUILD_JPIP_SERVER) add_library(openjpip_server STATIC ${OPENJPIP_SRCS} ${SERVER_SRCS}) + add_sanitizers(openjpip_server) target_link_libraries(openjpip_server ${FCGI_LIBRARIES} ${CURL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) set_target_properties(openjpip_server PROPERTIES COMPILE_FLAGS "-DSERVER") From 40e620ee525520288bffbef6bd0534a9a4dc4108 Mon Sep 17 00:00:00 2001 From: Karol Babioch Date: Wed, 28 Feb 2018 17:44:29 +0100 Subject: [PATCH 11/12] Add sanitizer support for openjpwl library --- src/lib/openjpwl/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/openjpwl/CMakeLists.txt b/src/lib/openjpwl/CMakeLists.txt index 1b33adbe..5c6208c1 100644 --- a/src/lib/openjpwl/CMakeLists.txt +++ b/src/lib/openjpwl/CMakeLists.txt @@ -46,6 +46,7 @@ if(WIN32) endif() endif() add_library(openjpwl ${JPWL_SRCS} ${OPENJPEG_SRCS}) +add_sanitizers(openjpwl) if(UNIX) target_link_libraries(openjpwl m) endif() From 2ce57debf63b59b652c284c456a0832c05f1155e Mon Sep 17 00:00:00 2001 From: Karol Babioch Date: Wed, 28 Feb 2018 17:44:40 +0100 Subject: [PATCH 12/12] Add sanitizer support for openmj2 library --- src/lib/openmj2/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/openmj2/CMakeLists.txt b/src/lib/openmj2/CMakeLists.txt index 25294b20..2054a534 100644 --- a/src/lib/openmj2/CMakeLists.txt +++ b/src/lib/openmj2/CMakeLists.txt @@ -40,6 +40,7 @@ endif() # build mj2 lib: add_library(${OPENMJ2_LIBRARY_NAME} ${OPENMJ2_SRCS}) +add_sanitizers(${OPENMJ2_LIBRARY_NAME}) # FIXME: We are using an openjpeg 1.5 copy: #target_link_libraries(${OPENMJ2_LIBRARY_NAME} openjp2) if(UNIX)