Skip to content

Commit

Permalink
fix: check for libcurl version and feature AsynchDNS (#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
supervacuus authored Mar 6, 2023
1 parent 7abe8d1 commit 1f14ef0
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**Fixes**:

- Remove OpenSSL as direct dependency for the crashpad backend on Linux. ([#812](https://github.com/getsentry/sentry-native/pull/812), [crashpad#81](https://github.com/getsentry/crashpad/pull/81))
- Check `libcurl` for feature `AsynchDNS` at compile- and runtime. ([#813](https://github.com/getsentry/sentry-native/pull/813))

## 0.6.0

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ endif()

if(SENTRY_TRANSPORT_CURL)
if(NOT CURL_FOUND) # Some other lib might bring libcurl already
find_package(CURL REQUIRED)
find_package(CURL REQUIRED COMPONENTS AsynchDNS)
endif()

if(TARGET CURL::libcurl) # Only available in cmake 3.12+
Expand Down
17 changes: 17 additions & 0 deletions src/sentry_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,20 @@ sentry__snprintf_c(char *buf, size_t buf_size, const char *fmt, ...)
va_end(args);
return rv;
}

bool
sentry__check_min_version(sentry_version_t actual, sentry_version_t expected)
{
if (actual.major < expected.major) {
return false;
}
if (actual.major == expected.major && actual.minor < expected.minor) {
return false;
}
if (actual.major == expected.major && actual.minor == expected.minor
&& actual.patch < expected.patch) {
return false;
}

return true;
}
16 changes: 16 additions & 0 deletions src/sentry_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,20 @@ double sentry__strtod_c(const char *ptr, char **endptr);
*/
int sentry__snprintf_c(char *buf, size_t buf_size, const char *fmt, ...);

/**
* Represents a version of a software artifact.
*/
typedef struct {
unsigned int major;
unsigned int minor;
unsigned int patch;
} sentry_version_t;

/**
* Checks whether `actual` is the same or a later version than `expected`.
* Returns `true` if that is the case.
*/
bool sentry__check_min_version(
sentry_version_t actual, sentry_version_t expected);

#endif
27 changes: 26 additions & 1 deletion src/transports/sentry_transport_curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include <curl/curl.h>
#include <curl/easy.h>
#include <stdlib.h>
#include <string.h>

typedef struct curl_transport_state_s {
Expand Down Expand Up @@ -67,6 +66,32 @@ sentry__curl_transport_start(
SENTRY_WARNF("`curl_global_init` failed with code `%d`", (int)rv);
return 1;
}

curl_version_info_data *version_data
= curl_version_info(CURLVERSION_NOW);

if (!version_data) {
SENTRY_WARN("Failed to retrieve `curl_version_info`");
return 1;
}

sentry_version_t curl_version = {
.major = (version_data->version_num >> 16) & 0xff,
.minor = (version_data->version_num >> 8) & 0xff,
.patch = version_data->version_num & 0xff,
};

if (!sentry__check_min_version(
curl_version, (sentry_version_t) { 7, 10, 7 })) {
SENTRY_WARNF("`libcurl` is at unsupported version `%u.%u.%u`",
curl_version.major, curl_version.minor, curl_version.patch);
return 1;
}

if ((version_data->features & CURL_VERSION_ASYNCHDNS) == 0) {
SENTRY_WARN("`libcurl` was not compiled with feature `AsynchDNS`");
return 1;
}
}

sentry_bgworker_t *bgworker = (sentry_bgworker_t *)transport_state;
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/test_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,32 @@ SENTRY_TEST(os)

sentry_value_decref(os);
}

SENTRY_TEST(check_version)
{
TEST_CHECK(sentry__check_min_version(
(sentry_version_t) { .major = 7, .minor = 10, .patch = 7 },
(sentry_version_t) { .major = 7, .minor = 10, .patch = 7 }));
TEST_CHECK(sentry__check_min_version(
(sentry_version_t) { .major = 7, .minor = 11, .patch = 7 },
(sentry_version_t) { .major = 7, .minor = 10, .patch = 7 }));
TEST_CHECK(sentry__check_min_version(
(sentry_version_t) { .major = 7, .minor = 10, .patch = 8 },
(sentry_version_t) { .major = 7, .minor = 10, .patch = 7 }));
TEST_CHECK(sentry__check_min_version(
(sentry_version_t) { .major = 8, .minor = 9, .patch = 7 },
(sentry_version_t) { .major = 7, .minor = 10, .patch = 7 }));
TEST_CHECK(sentry__check_min_version(
(sentry_version_t) { .major = 7, .minor = 11, .patch = 6 },
(sentry_version_t) { .major = 7, .minor = 10, .patch = 7 }));

TEST_CHECK(!sentry__check_min_version(
(sentry_version_t) { .major = 6, .minor = 10, .patch = 7 },
(sentry_version_t) { .major = 7, .minor = 10, .patch = 7 }));
TEST_CHECK(!sentry__check_min_version(
(sentry_version_t) { .major = 7, .minor = 9, .patch = 7 },
(sentry_version_t) { .major = 7, .minor = 10, .patch = 7 }));
TEST_CHECK(!sentry__check_min_version(
(sentry_version_t) { .major = 7, .minor = 10, .patch = 6 },
(sentry_version_t) { .major = 7, .minor = 10, .patch = 7 }));
}
5 changes: 3 additions & 2 deletions tests/unit/tests.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ XX(basic_tracing_context)
XX(basic_transaction)
XX(bgworker_flush)
XX(build_id_parser)
XX(check_version)
XX(child_spans)
XX(concurrent_init)
XX(concurrent_uninit)
XX(count_sampled_events)
XX(crashed_last_run)
XX(crash_marker)
XX(crashed_last_run)
XX(custom_logger)
XX(discarding_before_send)
XX(distributed_headers)
XX(drop_unfinished_spans)
XX(dsn_parsing_complete)
XX(dsn_parsing_invalid)
XX(dsn_store_url_without_path)
XX(dsn_store_url_with_path)
XX(dsn_store_url_without_path)
XX(empty_transport)
XX(fuzz_json)
XX(init_failure)
Expand Down

0 comments on commit 1f14ef0

Please sign in to comment.