From a501f65c8cc77b10bdf260593906a818f23e9632 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 29 Aug 2019 15:11:59 +0200 Subject: [PATCH] libcurl.cfg: Add library configuration for libcurl (#2120) Add curl_easy_*() functions and deprecated functions with warnings. Add tests and prepare donate-cpu.py Reference: https://curl.haxx.se/libcurl/c/ --- .travis.yml | 2 +- cfg/libcurl.cfg | 487 +++++++++++++++++++++++++++++++++++++++++++ test/cfg/libcurl.c | 86 ++++++++ test/cfg/runtests.sh | 27 +++ tools/donate-cpu.py | 1 + 5 files changed, 602 insertions(+), 1 deletion(-) create mode 100644 cfg/libcurl.cfg create mode 100644 test/cfg/libcurl.c diff --git a/.travis.yml b/.travis.yml index 51fd90d77..e3803d9f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ env: before_install: # install needed deps - travis_retry sudo apt-get update -qq - - travis_retry sudo apt-get install -qq python-pygments qt5-default qt5-qmake qtbase5-dev qtcreator libxml2-utils libpcre3 gdb unzip wx-common xmlstarlet python3-dev liblua5.3-dev + - travis_retry sudo apt-get install -qq python-pygments qt5-default qt5-qmake qtbase5-dev qtcreator libxml2-utils libpcre3 gdb unzip wx-common xmlstarlet python3-dev liblua5.3-dev libcurl3 - travis_retry python2 -m pip install --user pytest==4.6.4 - travis_retry python2 -m pip install --user pylint - travis_retry python2 -m pip install --user unittest2 diff --git a/cfg/libcurl.cfg b/cfg/libcurl.cfg new file mode 100644 index 000000000..381fbb237 --- /dev/null +++ b/cfg/libcurl.cfg @@ -0,0 +1,487 @@ + + + + + + + + + + + curl_easy_init + curl_easy_duphandle + curl_easy_cleanup + + + curl_easy_escape + curl_easy_unescape + curl_escape + curl_unescape + curl_free + + + curl_getenv + curl_maprintf + curl_mvaprintf + free + + + + + false + + + + + + + + + false + + + + + + + + + + false + + + + + + + + + + + + 0: + + + + + false + + + + + + + + + + + + + + + false + + + + + + false + + + + + + + + + + + + + false + + + + + + + + + + false + + + + + + + + + + + 0: + + + + + + + + + false + + + + + + + + + false + + + + + + + + + + + + 0: + + + + + + + + + false + + + + + + + + + + + + + + + false + + + + + + + + + + false + + + + + + + + + + 0: + + + + + + + + false + + + + + + + + + false + + + + + + + + + + 0: + + + + + false + + + + + + false + + + This function will be removed from the public libcurl API in a near future. It will instead be made "available" by source code access only, and then as curlx_getenv(). + + + + + + + + false + + + These functions will be removed from the public libcurl API in the future. Do not use them in any new programs or projects. + + + + + + + + + + false + + + + + + + + + + + + + + + false + + + + + + + + + + + + + false + + + + + + + + + 0: + + + + + + + + + + + + false + + + + + + + + + + + + + + + + false + + + Usage of curl_multi_socket is deprecated, whereas the function is equivalent to curl_multi_socket_action with ev_bitmask set to 0. + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + false + + These functions will be removed from the public libcurl API in the future. Do not use them in any new programs or projects. + + + + + + + + + + false + + + + + + + + + + + + + + + + false + + + + + + + + + + + + false + + + + + + + + + 0: + + + + + + + + + + + + false + + + + + + + + + + + + + + + false + + + + + These functions will be removed from the public libcurl API in a near future. They will instead be made "available" by source code access only, and then as curlx_strequal() and curlx_strenqual(). + + + + + + + + + + + + + + false + + + + + These functions will be removed from the public libcurl API in a near future. They will instead be made "available" by source code access only, and then as curlx_strequal() and curlx_strenqual(). + + + + + + + + + + + + 0: + + + + + false + + + + + + + + + + 0: + + + diff --git a/test/cfg/libcurl.c b/test/cfg/libcurl.c new file mode 100644 index 000000000..7205905f8 --- /dev/null +++ b/test/cfg/libcurl.c @@ -0,0 +1,86 @@ + +// Test library configuration for libcurl.cfg +// +// Usage: +// $ cppcheck --check-library --library=libcurl --enable=information --error-exitcode=1 --inline-suppr --suppress=missingIncludeSystem test/cfg/libcurl.c +// => +// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0 +// + +#include +#include + +void validCode() +{ + CURL *curl = curl_easy_init(); + if (curl) { + CURLcode res; + curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); + res = curl_easy_perform(curl); + if (res != CURLE_OK) { + printf("error"); + } else { + long response_code; + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); + printf("%ld", response_code); + char * pStr = curl_easy_escape(curl, "a", 1); + if (pStr) + printf("%s", pStr); + curl_free(pStr); + curl_easy_reset(curl); + } + curl_easy_cleanup(curl); + } +} + +void ignoredReturnValue(CURL * handle) +{ + // cppcheck-suppress ignoredReturnValue + curl_easy_strerror(1); +} + +void resourceLeak_curl_easy_init() +{ + CURL *curl = curl_easy_init(); + printf("%p", curl); + // cppcheck-suppress resourceLeak +} + +void resourceLeak_curl_easy_duphandle(CURL * handle) +{ + CURL *curl = curl_easy_duphandle(handle); + printf("%p", curl); + // cppcheck-suppress resourceLeak +} + +void memleak_curl_easy_escape(CURL * handle) +{ + char * pStr = curl_easy_escape(handle, "a", 1); + if (pStr) + printf("%s", pStr); + // cppcheck-suppress memleak +} + +void nullPointer(CURL * handle) +{ + char * buf[10] = {0}; + size_t len; + + curl_easy_recv(handle, buf, 10, &len); + // cppcheck-suppress nullPointer + curl_easy_recv(handle, buf, 10, NULL); + curl_easy_send(handle, buf, 10, &len); + // cppcheck-suppress nullPointer + curl_easy_send(handle, buf, 10, NULL); +} + +void uninitvar(CURL * handle) +{ + char * bufInit[10] = {0}; + char * bufUninit; + size_t len; + + curl_easy_send(handle, bufInit, 10, &len); + // cppcheck-suppress uninitvar + curl_easy_send(handle, bufUninit, 10, &len); +} diff --git a/test/cfg/runtests.sh b/test/cfg/runtests.sh index f6b337e61..3118a6f3f 100755 --- a/test/cfg/runtests.sh +++ b/test/cfg/runtests.sh @@ -226,6 +226,33 @@ else fi ${CPPCHECK} ${CPPCHECK_OPT} --library=lua ${DIR}lua.c +# libcurl.c +set +e +pkg-config --version +PKGCONFIG_RETURNCODE=$? +set -e +if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then + echo "pkg-config needed to retrieve libcurl configuration is not available, skipping syntax check." +else + set +e + LIBCURLCONFIG=$(pkg-config --cflags libcurl) + LIBCURLCONFIG_RETURNCODE=$? + set -e + if [ $LIBCURLCONFIG_RETURNCODE -eq 0 ]; then + set +e + echo -e "#include " | ${CC} ${CC_OPT} ${LIBCURLCONFIG} -x c - + LIBCURLCONFIG_RETURNCODE=$? + set -e + if [ $LIBCURLCONFIG_RETURNCODE -ne 0 ]; then + echo "libcurl not completely present or not working, skipping syntax check with ${CC}." + else + echo "libcurl found and working, checking syntax with ${CC} now." + ${CC} ${CC_OPT} ${LIBCURLCONFIG} ${DIR}libcurl.c + fi + fi +fi +${CPPCHECK} ${CPPCHECK_OPT} --library=libcurl ${DIR}libcurl.c + # Check the syntax of the defines in the configuration files set +e xmlstarlet --version diff --git a/tools/donate-cpu.py b/tools/donate-cpu.py index 49fa5bb34..d423a3dc3 100644 --- a/tools/donate-cpu.py +++ b/tools/donate-cpu.py @@ -273,6 +273,7 @@ def scan_package(work_path, cppcheck_path, jobs): 'googletest': [''], 'gtk': ['', '', ''], 'libcerror': [''], + # 'libcurl': [''], <= enable after release of version 1.89 # 'lua': ['', '"lua.h"'], <= enable after release of version 1.89 'microsoft_sal': [''], 'motif': ['