mirror of
https://github.com/libssh2/libssh2.git
synced 2025-07-23 16:21:00 +03:00
build: prepare builds for clang-cl, add cmake ossfuzz support
- cmake: add support to build ossfuzz. Enable with `-DBUILD_OSSFUZZ=ON`. Also supports `-DLIB_FUZZING_ENGINE=` like autotools does. - check for `__clang__` when suppressing warnings in source. Necessary for clang-cl, which set `__clang__`, but doesn't set `__GNU__`. - cmake: optimize out 4 picky warning option detections with gcc. - cmake: bring `-pedantic-error`, `-Wall` use closer to curl's. - cmake: set `-Wno-language-extension-token` for clang-cl. - cmake: escape only the necessary `-W` options for clang-cl. - cmake: apply picky warnings to C++. - cmake: replace `unset(VAR)` with `set(VAR "")` for init. - cmake: prefer dash-style MSVC options. - cmake: simplify `MATCHES` expression. - cmake: formatting/whitespace. - ci/GHA: bump `actions/upload-artifact` to v4 Closes #1524
This commit is contained in:
2
.github/workflows/cifuzz.yml
vendored
2
.github/workflows/cifuzz.yml
vendored
@ -31,7 +31,7 @@ jobs:
|
||||
dry-run: false
|
||||
language: c
|
||||
- name: Upload Crash
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
if: ${{ failure() && steps.build.outcome == 'success' }}
|
||||
with:
|
||||
name: artifacts
|
||||
|
@ -122,8 +122,9 @@ endif()
|
||||
|
||||
option(BUILD_EXAMPLES "Build libssh2 examples" ON)
|
||||
option(BUILD_TESTING "Build libssh2 test suite" ON)
|
||||
option(BUILD_OSSFUZZ "Build libssh2 OSS-Fuzz" OFF)
|
||||
|
||||
if(NOT BUILD_STATIC_LIBS AND NOT BUILD_SHARED_LIBS)
|
||||
if((NOT BUILD_STATIC_LIBS AND NOT BUILD_SHARED_LIBS) OR BUILD_OSSFUZZ)
|
||||
set(BUILD_STATIC_LIBS ON)
|
||||
endif()
|
||||
|
||||
@ -228,7 +229,7 @@ endif()
|
||||
# duration of these tests.
|
||||
if(MSVC AND ENABLE_WERROR)
|
||||
cmake_push_check_state()
|
||||
set(CMAKE_REQUIRED_FLAGS "/WX-")
|
||||
set(CMAKE_REQUIRED_FLAGS "-WX-")
|
||||
endif()
|
||||
|
||||
if(HAVE_SYS_TIME_H)
|
||||
|
@ -3,47 +3,48 @@
|
||||
|
||||
include(CheckCCompilerFlag)
|
||||
|
||||
set(_picky "")
|
||||
|
||||
option(ENABLE_WERROR "Turn compiler warnings into errors" OFF)
|
||||
option(PICKY_COMPILER "Enable picky compiler options" ON)
|
||||
|
||||
if(ENABLE_WERROR)
|
||||
if(MSVC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -WX")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -WX")
|
||||
else() # llvm/clang and gcc style options
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
|
||||
endif()
|
||||
|
||||
if(((CMAKE_COMPILER_IS_GNUCC AND
|
||||
NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0 AND
|
||||
NOT CMAKE_VERSION VERSION_LESS 3.23.0) OR # to avoid check_symbol_exists() conflicting with GCC -pedantic-errors
|
||||
CMAKE_C_COMPILER_ID MATCHES "Clang"))
|
||||
list(APPEND _picky "-pedantic-errors")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
# Use the highest warning level for Visual Studio.
|
||||
if(PICKY_COMPILER)
|
||||
if(CMAKE_CXX_FLAGS MATCHES "[/-]W[0-4]")
|
||||
string(REGEX REPLACE "[/-]W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
||||
endif()
|
||||
if(CMAKE_C_FLAGS MATCHES "[/-]W[0-4]")
|
||||
string(REGEX REPLACE "[/-]W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
||||
string(REGEX REPLACE "[/-]W[0-4]" "-W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
||||
else()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W4")
|
||||
endif()
|
||||
if(CMAKE_CXX_FLAGS MATCHES "[/-]W[0-4]")
|
||||
string(REGEX REPLACE "[/-]W[0-4]" "-W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W4")
|
||||
endif()
|
||||
endif()
|
||||
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||
|
||||
if(PICKY_COMPILER)
|
||||
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||
|
||||
# https://clang.llvm.org/docs/DiagnosticsReference.html
|
||||
# https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
|
||||
|
||||
if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
||||
endif()
|
||||
if(NOT CMAKE_C_FLAGS MATCHES "-Wall")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
|
||||
endif()
|
||||
|
||||
if(PICKY_COMPILER)
|
||||
|
||||
# _picky_enable = Options we want to enable as-is.
|
||||
# _picky_detect = Options we want to test first and enable if available.
|
||||
|
||||
@ -55,15 +56,9 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_I
|
||||
endif()
|
||||
|
||||
list(APPEND _picky_enable
|
||||
-pedantic
|
||||
-Wall -pedantic
|
||||
)
|
||||
|
||||
if(ENABLE_WERROR)
|
||||
list(APPEND _picky_enable
|
||||
-pedantic-errors
|
||||
)
|
||||
endif()
|
||||
|
||||
# ----------------------------------
|
||||
# Add new options here, if in doubt:
|
||||
# ----------------------------------
|
||||
@ -119,29 +114,29 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_I
|
||||
-Wvla # clang 2.8 gcc 4.3
|
||||
)
|
||||
|
||||
set(_picky_common
|
||||
-Wdouble-promotion # clang 3.6 gcc 4.6 appleclang 6.3
|
||||
-Wenum-conversion # clang 3.2 gcc 10.0 appleclang 4.6 g++ 11.0
|
||||
-Wpragmas # clang 3.5 gcc 4.1 appleclang 6.0
|
||||
-Wunused-const-variable # clang 3.4 gcc 6.0 appleclang 5.1
|
||||
)
|
||||
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||
list(APPEND _picky_enable
|
||||
${_picky_common_old}
|
||||
-Wshift-sign-overflow # clang 2.9
|
||||
-Wshorten-64-to-32 # clang 1.0
|
||||
-Wlanguage-extension-token # clang 3.0
|
||||
-Wformat=2 # clang 3.0 gcc 4.8
|
||||
)
|
||||
if(NOT MSVC)
|
||||
list(APPEND _picky_enable
|
||||
-Wlanguage-extension-token # clang 3.0
|
||||
)
|
||||
endif()
|
||||
# Enable based on compiler version
|
||||
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.6) OR
|
||||
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.3))
|
||||
list(APPEND _picky_enable
|
||||
${_picky_common}
|
||||
# -Wunreachable-code-break # clang 3.5 appleclang 6.0 # Not used: Silent in "unity" builds
|
||||
-Wdouble-promotion # clang 3.6 gcc 4.6 appleclang 6.3
|
||||
-Wenum-conversion # clang 3.2 gcc 10.0 appleclang 4.6 g++ 11.0
|
||||
-Wheader-guard # clang 3.4 appleclang 5.1
|
||||
-Wpragmas # clang 3.5 gcc 4.1 appleclang 6.0
|
||||
-Wsometimes-uninitialized # clang 3.2 appleclang 4.6
|
||||
# -Wunreachable-code-break # clang 3.5 appleclang 6.0 # Not used: Silent in "unity" builds
|
||||
-Wunused-const-variable # clang 3.4 gcc 6.0 appleclang 5.1
|
||||
)
|
||||
endif()
|
||||
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.9) OR
|
||||
@ -165,9 +160,6 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_I
|
||||
)
|
||||
endif()
|
||||
else() # gcc
|
||||
list(APPEND _picky_detect
|
||||
${_picky_common}
|
||||
)
|
||||
# Enable based on compiler version
|
||||
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.3)
|
||||
list(APPEND _picky_enable
|
||||
@ -175,8 +167,8 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_I
|
||||
-Wclobbered # gcc 4.3
|
||||
-Wmissing-parameter-type # gcc 4.3
|
||||
-Wold-style-declaration # gcc 4.3
|
||||
-Wpragmas # clang 3.5 gcc 4.1 appleclang 6.0
|
||||
-Wstrict-aliasing=3 # gcc 4.0
|
||||
-Wtrampolines # gcc 4.3
|
||||
)
|
||||
endif()
|
||||
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.5 AND MINGW)
|
||||
@ -186,7 +178,9 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_I
|
||||
endif()
|
||||
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8)
|
||||
list(APPEND _picky_enable
|
||||
-Wdouble-promotion # clang 3.6 gcc 4.6 appleclang 6.3
|
||||
-Wformat=2 # clang 3.0 gcc 4.8
|
||||
-Wtrampolines # gcc 4.6
|
||||
)
|
||||
endif()
|
||||
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0)
|
||||
@ -201,6 +195,7 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_I
|
||||
-fdelete-null-pointer-checks
|
||||
-Wshift-negative-value # clang 3.7 gcc 6.0 (clang default)
|
||||
-Wshift-overflow=2 # clang 3.0 gcc 6.0 (clang default: -Wshift-overflow)
|
||||
-Wunused-const-variable # clang 3.4 gcc 6.0 appleclang 5.1
|
||||
)
|
||||
endif()
|
||||
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 7.0)
|
||||
@ -216,14 +211,13 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_I
|
||||
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0)
|
||||
list(APPEND _picky_enable
|
||||
-Warith-conversion # gcc 10.0
|
||||
-Wenum-conversion # clang 3.2 gcc 10.0 appleclang 4.6 g++ 11.0
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#
|
||||
|
||||
unset(_picky)
|
||||
|
||||
foreach(_ccopt IN LISTS _picky_enable)
|
||||
list(APPEND _picky "${_ccopt}")
|
||||
endforeach()
|
||||
@ -239,24 +233,28 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_I
|
||||
list(APPEND _picky "${_ccopt}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# clang-cl
|
||||
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND MSVC)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.12)
|
||||
list(APPEND _picky "-Wno-language-extension-token") # Allow __int64
|
||||
|
||||
set(_picky_tmp "")
|
||||
foreach(_ccopt IN LISTS _picky)
|
||||
list(APPEND _picky_tmp "/clang:${_ccopt}")
|
||||
# Prefix -Wall, otherwise clang-cl interprets it as an MSVC option and translates it to -Weverything
|
||||
if(_ccopt MATCHES "^-W" AND NOT _ccopt STREQUAL "-Wall")
|
||||
list(APPEND _picky_tmp ${_ccopt})
|
||||
else()
|
||||
list(APPEND _picky_tmp "-clang:${_ccopt}")
|
||||
endif()
|
||||
endforeach()
|
||||
set(_picky ${_picky_tmp})
|
||||
else()
|
||||
list(TRANSFORM _picky PREPEND "/clang:")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(_picky)
|
||||
string(REPLACE ";" " " _picky "${_picky}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_picky}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_picky}")
|
||||
message(STATUS "Picky compiler options: ${_picky}")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
@ -248,12 +248,12 @@ int main(int argc, char *argv[])
|
||||
for(;;) {
|
||||
fd_set fds;
|
||||
FD_ZERO(&fds);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(forwardsock, &fds);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
tv.tv_sec = 0;
|
||||
@ -263,12 +263,12 @@ int main(int argc, char *argv[])
|
||||
fprintf(stderr, "failed to select().\n");
|
||||
goto shutdown;
|
||||
}
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
if(rc && FD_ISSET(forwardsock, &fds)) {
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
len = recv(forwardsock, buf, sizeof(buf), 0);
|
||||
|
@ -64,12 +64,12 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
||||
|
||||
FD_ZERO(&fd);
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(socket_fd, &fd);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
|
@ -48,12 +48,12 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
||||
|
||||
FD_ZERO(&fd);
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(socket_fd, &fd);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
|
@ -56,12 +56,12 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
||||
|
||||
FD_ZERO(&fd);
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(socket_fd, &fd);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
@ -258,13 +258,13 @@ int main(int argc, char *argv[])
|
||||
|
||||
FD_ZERO(&fd);
|
||||
FD_ZERO(&fd2);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(sock, &fd);
|
||||
FD_SET(sock, &fd2);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
@ -329,13 +329,13 @@ int main(int argc, char *argv[])
|
||||
|
||||
FD_ZERO(&fd);
|
||||
FD_ZERO(&fd2);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(sock, &fd);
|
||||
FD_SET(sock, &fd2);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
|
@ -65,12 +65,12 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
||||
|
||||
FD_ZERO(&fd);
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(socket_fd, &fd);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
|
@ -54,12 +54,12 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
||||
|
||||
FD_ZERO(&fd);
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(socket_fd, &fd);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
|
@ -55,12 +55,12 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
||||
|
||||
FD_ZERO(&fd);
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(socket_fd, &fd);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
|
@ -50,12 +50,12 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
||||
|
||||
FD_ZERO(&fd);
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(socket_fd, &fd);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
|
@ -47,12 +47,12 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
||||
|
||||
FD_ZERO(&fd);
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(socket_fd, &fd);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
|
@ -51,12 +51,12 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
||||
|
||||
FD_ZERO(&fd);
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(socket_fd, &fd);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
|
@ -246,12 +246,12 @@ int main(int argc, char *argv[])
|
||||
for(;;) {
|
||||
fd_set fds;
|
||||
FD_ZERO(&fds);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(forwardsock, &fds);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
tv.tv_sec = 0;
|
||||
@ -261,12 +261,12 @@ int main(int argc, char *argv[])
|
||||
fprintf(stderr, "failed to select().\n");
|
||||
goto shutdown;
|
||||
}
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
if(rc && FD_ISSET(forwardsock, &fds)) {
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
ssize_t nwritten;
|
||||
|
@ -210,12 +210,12 @@ static int x11_send_receive(LIBSSH2_CHANNEL *channel, libssh2_socket_t sock)
|
||||
timeval_out.tv_usec = 0;
|
||||
|
||||
FD_ZERO(&set);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(sock, &set);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
@ -415,12 +415,12 @@ int main(int argc, char *argv[])
|
||||
for(;;) {
|
||||
|
||||
FD_ZERO(&set);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(fileno(stdin), &set);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
|
@ -49,7 +49,7 @@ endif()
|
||||
|
||||
## Options
|
||||
|
||||
unset(_libssh2_definitions)
|
||||
set(_libssh2_definitions "")
|
||||
|
||||
option(CLEAR_MEMORY "Enable clearing of memory before being freed" ON)
|
||||
if(NOT CLEAR_MEMORY)
|
||||
@ -76,8 +76,8 @@ list(APPEND LIBSSH2_LIBS ${LIBSSH2_LIBS_SOCKET})
|
||||
list(APPEND libssh2_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
if(MSVC)
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Zi /Od")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /DEBUG")
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Zi -Od")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -DEBUG")
|
||||
endif()
|
||||
|
||||
## Sources
|
||||
@ -100,7 +100,7 @@ if(WIN32 AND (BUILD_STATIC_LIBS OR BUILD_STATIC_FOR_TESTS) AND BUILD_SHARED_LIBS
|
||||
set(STATIC_LIB_SUFFIX "_static")
|
||||
endif()
|
||||
|
||||
unset(_libssh2_export)
|
||||
set(_libssh2_export "")
|
||||
|
||||
# we want it to be called libssh2 on all platforms
|
||||
if(BUILD_STATIC_LIBS OR BUILD_STATIC_FOR_TESTS)
|
||||
@ -212,7 +212,7 @@ endif()
|
||||
set(_ldflags "")
|
||||
|
||||
# Avoid getting unnecessary -L options for known system directories.
|
||||
unset(_sys_libdirs)
|
||||
set(_sys_libdirs "")
|
||||
foreach(_libdir IN LISTS CMAKE_SYSTEM_PREFIX_PATH)
|
||||
if(_libdir MATCHES "/$")
|
||||
set(_libdir "${_libdir}lib")
|
||||
@ -237,7 +237,7 @@ foreach(_libdir IN LISTS LIBSSH2_LIBDIRS)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
unset(_implicit_libs)
|
||||
set(_implicit_libs "")
|
||||
if(NOT MINGW AND NOT UNIX)
|
||||
set(_implicit_libs ${CMAKE_C_IMPLICIT_LINK_LIBRARIES})
|
||||
endif()
|
||||
@ -259,7 +259,7 @@ foreach(_lib IN LISTS _implicit_libs LIBSSH2_LIBS)
|
||||
endif()
|
||||
if(_lib MATCHES "^-")
|
||||
list(APPEND _ldflags "${_lib}")
|
||||
elseif(_lib MATCHES ".*/.*")
|
||||
elseif(_lib MATCHES "/")
|
||||
# This gets a bit more complex, because we want to specify the
|
||||
# directory separately, and only once per directory
|
||||
get_filename_component(_libdir ${_lib} DIRECTORY)
|
||||
|
@ -45,7 +45,7 @@
|
||||
|
||||
/* FIXME: Disable warnings for 'src' */
|
||||
#if !defined(LIBSSH2_TESTS) && !defined(LIBSSH2_WARN_SIGN_CONVERSION)
|
||||
#ifdef __GNUC__
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
#endif
|
||||
|
@ -41,7 +41,7 @@
|
||||
|
||||
#define LIBSSH2_CRYPTO_ENGINE libssh2_mbedtls
|
||||
|
||||
#ifdef __GNUC__
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
/* mbedTLS (as of v3.5.1) has a `[-Werror=arith-conversion]`
|
||||
warning in its public headers. */
|
||||
@ -73,7 +73,7 @@
|
||||
#include <mbedtls/pk.h>
|
||||
#include <mbedtls/error.h>
|
||||
|
||||
#ifdef __GNUC__
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
|
@ -675,12 +675,12 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time)
|
||||
|
||||
if(dir & LIBSSH2_SESSION_BLOCK_INBOUND) {
|
||||
FD_ZERO(&rfd);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(session->socket_fd, &rfd);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
readfd = &rfd;
|
||||
@ -688,12 +688,12 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time)
|
||||
|
||||
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) {
|
||||
FD_ZERO(&wfd);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(session->socket_fd, &wfd);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
writefd = &wfd;
|
||||
@ -1655,24 +1655,24 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
|
||||
switch(fds[i].type) {
|
||||
case LIBSSH2_POLLFD_SOCKET:
|
||||
if(fds[i].events & LIBSSH2_POLLFD_POLLIN) {
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(fds[i].fd.socket, &rfds);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
if(fds[i].fd.socket > maxfd)
|
||||
maxfd = fds[i].fd.socket;
|
||||
}
|
||||
if(fds[i].events & LIBSSH2_POLLFD_POLLOUT) {
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(fds[i].fd.socket, &wfds);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
if(fds[i].fd.socket > maxfd)
|
||||
@ -1681,12 +1681,12 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
|
||||
break;
|
||||
|
||||
case LIBSSH2_POLLFD_CHANNEL:
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(fds[i].fd.channel->session->socket_fd, &rfds);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
if(fds[i].fd.channel->session->socket_fd > maxfd)
|
||||
@ -1696,12 +1696,12 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
|
||||
break;
|
||||
|
||||
case LIBSSH2_POLLFD_LISTENER:
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
FD_SET(fds[i].fd.listener->session->socket_fd, &rfds);
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
if(fds[i].fd.listener->session->socket_fd > maxfd)
|
||||
@ -1880,7 +1880,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
|
||||
for(i = 0; i < nfds; i++) {
|
||||
switch(fds[i].type) {
|
||||
case LIBSSH2_POLLFD_SOCKET:
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
@ -1893,7 +1893,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
|
||||
if(fds[i].revents) {
|
||||
active_fds++;
|
||||
}
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
break;
|
||||
|
@ -85,7 +85,7 @@ foreach(_test IN LISTS DOCKER_TESTS STANDALONE_TESTS SSHD_TESTS)
|
||||
elseif(TARGET ${LIB_STATIC})
|
||||
set(_lib_for_tests ${LIB_STATIC})
|
||||
else()
|
||||
unset(_lib_for_tests)
|
||||
set(_lib_for_tests "")
|
||||
message(STATUS "Skip test requiring static libssh2 lib: ${_test}")
|
||||
endif()
|
||||
|
||||
@ -132,7 +132,7 @@ foreach(_test IN LISTS STANDALONE_TESTS)
|
||||
endforeach()
|
||||
|
||||
if(RUN_SSHD_TESTS AND SSHD_EXECUTABLE)
|
||||
unset(_sshd_test_targets)
|
||||
set(_sshd_test_targets "")
|
||||
foreach(_test IN LISTS SSHD_TESTS)
|
||||
if(TARGET ${_test})
|
||||
set(_sshd_test_targets "${_sshd_test_targets} $<TARGET_FILE:${_test}>")
|
||||
@ -176,3 +176,7 @@ add_target_to_copy_dependencies(
|
||||
TARGET copy_test_dependencies
|
||||
DEPENDENCIES ${RUNTIME_DEPENDENCIES}
|
||||
BEFORE_TARGETS ${TEST_TARGETS})
|
||||
|
||||
if(BUILD_OSSFUZZ)
|
||||
add_subdirectory(ossfuzz)
|
||||
endif()
|
||||
|
24
tests/ossfuzz/CMakeLists.txt
Normal file
24
tests/ossfuzz/CMakeLists.txt
Normal file
@ -0,0 +1,24 @@
|
||||
# Copyright (C) Viktor Szakats
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
enable_language(CXX)
|
||||
|
||||
add_library(standaloneengine STATIC "standaloneengine.cc")
|
||||
target_include_directories(standaloneengine PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/include")
|
||||
set_target_properties(standaloneengine PROPERTIES UNITY_BUILD OFF)
|
||||
|
||||
add_executable(ssh2_client_fuzzer "ssh2_client_fuzzer.cc" "testinput.h")
|
||||
target_include_directories(ssh2_client_fuzzer PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/include")
|
||||
if(LIB_FUZZING_ENGINE)
|
||||
if(LIB_FUZZING_ENGINE STREQUAL "-fsanitize=fuzzer") # FIXME: compiler-specific
|
||||
set_target_properties(ssh2_client_fuzzer PROPERTIES LINK_FLAGS "${LIB_FUZZING_ENGINE}")
|
||||
else()
|
||||
target_link_libraries(ssh2_client_fuzzer ${LIB_FUZZING_ENGINE})
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(ssh2_client_fuzzer standaloneengine)
|
||||
endif()
|
||||
target_link_libraries(ssh2_client_fuzzer ${LIB_STATIC} ${LIBSSH2_LIBS_SOCKET})
|
||||
set_target_properties(ssh2_client_fuzzer PROPERTIES UNITY_BUILD OFF)
|
@ -31,4 +31,4 @@ ssh2_client_fuzzer_LDFLAGS = $(AM_LDFLAGS) -static
|
||||
libstandaloneengine_a_SOURCES = standaloneengine.cc
|
||||
libstandaloneengine_a_CXXFLAGS = $(AM_CXXFLAGS)
|
||||
|
||||
EXTRA_DIST = ossfuzz.sh
|
||||
EXTRA_DIST = CMakeLists.txt ossfuzz.sh
|
||||
|
Reference in New Issue
Block a user