Skip to content

Commit 1f14ef0

Browse files
authored
fix: check for libcurl version and feature AsynchDNS (#813)
1 parent 7abe8d1 commit 1f14ef0

File tree

7 files changed

+93
-4
lines changed

7 files changed

+93
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
**Fixes**:
66

77
- 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))
8+
- Check `libcurl` for feature `AsynchDNS` at compile- and runtime. ([#813](https://github.com/getsentry/sentry-native/pull/813))
89

910
## 0.6.0
1011

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ endif()
274274

275275
if(SENTRY_TRANSPORT_CURL)
276276
if(NOT CURL_FOUND) # Some other lib might bring libcurl already
277-
find_package(CURL REQUIRED)
277+
find_package(CURL REQUIRED COMPONENTS AsynchDNS)
278278
endif()
279279

280280
if(TARGET CURL::libcurl) # Only available in cmake 3.12+

src/sentry_utils.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,3 +529,20 @@ sentry__snprintf_c(char *buf, size_t buf_size, const char *fmt, ...)
529529
va_end(args);
530530
return rv;
531531
}
532+
533+
bool
534+
sentry__check_min_version(sentry_version_t actual, sentry_version_t expected)
535+
{
536+
if (actual.major < expected.major) {
537+
return false;
538+
}
539+
if (actual.major == expected.major && actual.minor < expected.minor) {
540+
return false;
541+
}
542+
if (actual.major == expected.major && actual.minor == expected.minor
543+
&& actual.patch < expected.patch) {
544+
return false;
545+
}
546+
547+
return true;
548+
}

src/sentry_utils.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,20 @@ double sentry__strtod_c(const char *ptr, char **endptr);
198198
*/
199199
int sentry__snprintf_c(char *buf, size_t buf_size, const char *fmt, ...);
200200

201+
/**
202+
* Represents a version of a software artifact.
203+
*/
204+
typedef struct {
205+
unsigned int major;
206+
unsigned int minor;
207+
unsigned int patch;
208+
} sentry_version_t;
209+
210+
/**
211+
* Checks whether `actual` is the same or a later version than `expected`.
212+
* Returns `true` if that is the case.
213+
*/
214+
bool sentry__check_min_version(
215+
sentry_version_t actual, sentry_version_t expected);
216+
201217
#endif

src/transports/sentry_transport_curl.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <curl/curl.h>
1313
#include <curl/easy.h>
14-
#include <stdlib.h>
1514
#include <string.h>
1615

1716
typedef struct curl_transport_state_s {
@@ -67,6 +66,32 @@ sentry__curl_transport_start(
6766
SENTRY_WARNF("`curl_global_init` failed with code `%d`", (int)rv);
6867
return 1;
6968
}
69+
70+
curl_version_info_data *version_data
71+
= curl_version_info(CURLVERSION_NOW);
72+
73+
if (!version_data) {
74+
SENTRY_WARN("Failed to retrieve `curl_version_info`");
75+
return 1;
76+
}
77+
78+
sentry_version_t curl_version = {
79+
.major = (version_data->version_num >> 16) & 0xff,
80+
.minor = (version_data->version_num >> 8) & 0xff,
81+
.patch = version_data->version_num & 0xff,
82+
};
83+
84+
if (!sentry__check_min_version(
85+
curl_version, (sentry_version_t) { 7, 10, 7 })) {
86+
SENTRY_WARNF("`libcurl` is at unsupported version `%u.%u.%u`",
87+
curl_version.major, curl_version.minor, curl_version.patch);
88+
return 1;
89+
}
90+
91+
if ((version_data->features & CURL_VERSION_ASYNCHDNS) == 0) {
92+
SENTRY_WARN("`libcurl` was not compiled with feature `AsynchDNS`");
93+
return 1;
94+
}
7095
}
7196

7297
sentry_bgworker_t *bgworker = (sentry_bgworker_t *)transport_state;

tests/unit/test_utils.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,32 @@ SENTRY_TEST(os)
221221

222222
sentry_value_decref(os);
223223
}
224+
225+
SENTRY_TEST(check_version)
226+
{
227+
TEST_CHECK(sentry__check_min_version(
228+
(sentry_version_t) { .major = 7, .minor = 10, .patch = 7 },
229+
(sentry_version_t) { .major = 7, .minor = 10, .patch = 7 }));
230+
TEST_CHECK(sentry__check_min_version(
231+
(sentry_version_t) { .major = 7, .minor = 11, .patch = 7 },
232+
(sentry_version_t) { .major = 7, .minor = 10, .patch = 7 }));
233+
TEST_CHECK(sentry__check_min_version(
234+
(sentry_version_t) { .major = 7, .minor = 10, .patch = 8 },
235+
(sentry_version_t) { .major = 7, .minor = 10, .patch = 7 }));
236+
TEST_CHECK(sentry__check_min_version(
237+
(sentry_version_t) { .major = 8, .minor = 9, .patch = 7 },
238+
(sentry_version_t) { .major = 7, .minor = 10, .patch = 7 }));
239+
TEST_CHECK(sentry__check_min_version(
240+
(sentry_version_t) { .major = 7, .minor = 11, .patch = 6 },
241+
(sentry_version_t) { .major = 7, .minor = 10, .patch = 7 }));
242+
243+
TEST_CHECK(!sentry__check_min_version(
244+
(sentry_version_t) { .major = 6, .minor = 10, .patch = 7 },
245+
(sentry_version_t) { .major = 7, .minor = 10, .patch = 7 }));
246+
TEST_CHECK(!sentry__check_min_version(
247+
(sentry_version_t) { .major = 7, .minor = 9, .patch = 7 },
248+
(sentry_version_t) { .major = 7, .minor = 10, .patch = 7 }));
249+
TEST_CHECK(!sentry__check_min_version(
250+
(sentry_version_t) { .major = 7, .minor = 10, .patch = 6 },
251+
(sentry_version_t) { .major = 7, .minor = 10, .patch = 7 }));
252+
}

tests/unit/tests.inc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ XX(basic_tracing_context)
1414
XX(basic_transaction)
1515
XX(bgworker_flush)
1616
XX(build_id_parser)
17+
XX(check_version)
1718
XX(child_spans)
1819
XX(concurrent_init)
1920
XX(concurrent_uninit)
2021
XX(count_sampled_events)
21-
XX(crashed_last_run)
2222
XX(crash_marker)
23+
XX(crashed_last_run)
2324
XX(custom_logger)
2425
XX(discarding_before_send)
2526
XX(distributed_headers)
2627
XX(drop_unfinished_spans)
2728
XX(dsn_parsing_complete)
2829
XX(dsn_parsing_invalid)
29-
XX(dsn_store_url_without_path)
3030
XX(dsn_store_url_with_path)
31+
XX(dsn_store_url_without_path)
3132
XX(empty_transport)
3233
XX(fuzz_json)
3334
XX(init_failure)

0 commit comments

Comments
 (0)