diff --git a/CHANGELOG.md b/CHANGELOG.md index a960cc7b1..aa6673471 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,13 +10,8 @@ **Fixes**: - Name `sentry-logs` and `sentry-metrics` telemetry batcher threads so they can be identified in debuggers, profilers, and crash reports. ([#1937](https://github.com/getsentry/sentry-native/pull/1937)) - -**Fixes**: - +- Linux: close descriptor `0` on failed module file mapping when that descriptor was returned by `open`, avoiding a file descriptor leak. ([#1924](https://github.com/getsentry/sentry-native/pull/1924)) - `sentry_attachment_set_filename`, `sentry_attachment_set_type`, and `sentry_attachment_set_content_type` now flush the scope, so changes applied after `sentry_attach_file`/`sentry_attach_bytes` also apply to hard-crash events instead of only to normal events. ([#1934](https://github.com/getsentry/sentry-native/pull/1934)) - -**Fixes**: - - Crashpad: fix a crash when calling `sentry_init` before C++ dynamic initializers have run. ([#1930](https://github.com/getsentry/sentry-native/issues/1930), [mini_chromium#8](https://github.com/getsentry/mini_chromium/pull/8)) ## 0.16.1 diff --git a/src/modulefinder/sentry_modulefinder_linux.c b/src/modulefinder/sentry_modulefinder_linux.c index b2f9ddd9d..7dc6884b2 100644 --- a/src/modulefinder/sentry_modulefinder_linux.c +++ b/src/modulefinder/sentry_modulefinder_linux.c @@ -74,7 +74,7 @@ sentry__mmap_file(sentry_mmap_t *rv, const char *path) return true; fail: - if (fd > 0) { + if (fd >= 0) { close(fd); } rv->ptr = NULL; diff --git a/src/modulefinder/sentry_modulefinder_linux.h b/src/modulefinder/sentry_modulefinder_linux.h index c063825a3..90c58c397 100644 --- a/src/modulefinder/sentry_modulefinder_linux.h +++ b/src/modulefinder/sentry_modulefinder_linux.h @@ -52,6 +52,8 @@ void sentry__module_mapping_push( sentry_module_t *module, const sentry_parsed_module_t *parsed); #ifdef SENTRY_UNITTEST +bool sentry__mmap_file(sentry_mmap_t *rv, const char *path); + bool sentry__procmaps_read_ids_from_elf( sentry_value_t value, const sentry_module_t *module); diff --git a/tests/unit/test_modulefinder.c b/tests/unit/test_modulefinder.c index 563f49bae..3173c3ba1 100644 --- a/tests/unit/test_modulefinder.c +++ b/tests/unit/test_modulefinder.c @@ -4,6 +4,9 @@ #ifdef SENTRY_PLATFORM_LINUX # include "modulefinder/sentry_modulefinder_linux.h" +# include +# include +# include #endif SENTRY_TEST(module_finder) @@ -74,6 +77,33 @@ SENTRY_TEST(module_addr) #endif } +SENTRY_TEST(mmap_file_closes_fd_zero_on_failure) +{ +#if !defined(SENTRY_PLATFORM_LINUX) || defined(SENTRY_PLATFORM_ANDROID) + SKIP_TEST(); +#else + char tmp_path[] = "/tmp/sentry-native-mmap-XXXXXX"; + int tmp_fd = mkstemp(tmp_path); + TEST_ASSERT(tmp_fd >= 0); + close(tmp_fd); + + int saved_stdin = dup(STDIN_FILENO); + TEST_ASSERT(saved_stdin >= 0); + close(STDIN_FILENO); + + sentry_mmap_t mmap = { 0 }; + bool mapped = sentry__mmap_file(&mmap, tmp_path); + int fd_flags = fcntl(STDIN_FILENO, F_GETFD); + + dup2(saved_stdin, STDIN_FILENO); + close(saved_stdin); + unlink(tmp_path); + + TEST_CHECK(!mapped); + TEST_CHECK(fd_flags == -1); +#endif +} + SENTRY_TEST(procmaps_parser) { #if !defined(SENTRY_PLATFORM_LINUX) || __SIZEOF_POINTER__ != 8 diff --git a/tests/unit/tests.inc b/tests/unit/tests.inc index 1237f487a..5f0265802 100644 --- a/tests/unit/tests.inc +++ b/tests/unit/tests.inc @@ -229,6 +229,7 @@ XX(minidump_stream_types) XX(minidump_structures_packed) XX(minidump_system_info) XX(minidump_thread_structure) +XX(mmap_file_closes_fd_zero_on_failure) XX(module_addr) XX(module_finder) XX(mpack_newlines)