mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-24 12:04:40 +00:00
Merge branch 'metsw24-max-mmap-map-failed-guard'
This commit is contained in:
commit
f51df1473b
2 files changed
+25
No files matched your search
@@ -5576,6 +5576,14 @@ inline bool mmap::open(const char *path) {
|
|||||||
is_open_empty_file = true;
|
is_open_empty_file = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (addr_ == MAP_FAILED) {
|
||||||
|
// Clear the sentinel before `close()`, since `is_open()` only checks
|
||||||
|
// `addr_` against nullptr and `munmap()` must not be called with it.
|
||||||
|
addr_ = nullptr;
|
||||||
|
close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -9346,6 +9346,23 @@ TEST(MmapTest, OpenWhileFileHeldForWriting) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
// A failed ::mmap() must not be reported as an open mapping, otherwise data()
|
||||||
|
// hands the caller the MAP_FAILED sentinel. A directory is the easiest way to
|
||||||
|
// reach it, since ::open() and fstat() succeed for one but ::mmap() doesn't.
|
||||||
|
TEST(MmapTest, FailedMappingIsNotOpen) {
|
||||||
|
const char *path = "./mmap_failed_mapping_test_dir";
|
||||||
|
ASSERT_EQ(0, ::mkdir(path, 0755));
|
||||||
|
auto dir_cleanup = detail::scope_exit([&] { ::rmdir(path); });
|
||||||
|
|
||||||
|
detail::mmap m(path);
|
||||||
|
EXPECT_FALSE(m.is_open());
|
||||||
|
EXPECT_EQ(0U, m.size());
|
||||||
|
EXPECT_NE(static_cast<const void *>(m.data()),
|
||||||
|
static_cast<const void *>(MAP_FAILED));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
TEST(KeepAliveTest, ReadTimeout) {
|
TEST(KeepAliveTest, ReadTimeout) {
|
||||||
Server svr;
|
Server svr;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user