File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed
Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 2525# include <dlfcn.h>
2626#endif
2727
28+ /* FreeBSD may cause a segfault: https://reviews.freebsd.org/D5112,
29+ * DragonFlyBSD as well, so we need to check a file size before calling dlopen()
30+ */
31+ #if defined (P_OS_FREEBSD ) || defined (P_OS_DRAGONFLY )
32+ # include <unistd.h>
33+ # include <sys/types.h>
34+ # include <sys/stat.h>
35+ #endif
36+
2837#ifdef P_OS_WIN
2938 typedef HINSTANCE plibrary_handle ;
3039#else
@@ -54,12 +63,27 @@ p_library_loader_new (const pchar *path)
5463{
5564 PLibraryLoader * loader ;
5665 plibrary_handle handle ;
66+ #if defined (P_OS_FREEBSD ) || defined (P_OS_DRAGONFLY )
67+ struct stat stat_buf ;
68+ #endif
5769
5870 loader = NULL ;
5971
6072 if (!p_file_is_exists (path ))
6173 return NULL ;
6274
75+ #if defined (P_OS_FREEBSD ) || defined (P_OS_DRAGONFLY )
76+ if (P_UNLIKELY (stat (path , & stat_buf ) != 0 )) {
77+ P_ERROR ("PLibraryLoader: failed to call stat()" );
78+ return NULL ;
79+ }
80+
81+ if (P_UNLIKELY (stat_buf .st_size == 0 )) {
82+ P_ERROR ("PLibraryLoader: unable to handle zero-size file" );
83+ return NULL ;
84+ }
85+ #endif
86+
6387#ifdef P_OS_WIN
6488 if (P_UNLIKELY ((handle = LoadLibraryA (path )) == NULL )) {
6589 P_ERROR ("PLibraryLoader: failed to call LoadLibraryA()" );
Original file line number Diff line number Diff line change @@ -79,10 +79,7 @@ BOOST_AUTO_TEST_CASE (plibraryloader_nomem_test)
7979
8080 int argCount = boost::unit_test::framework::master_test_suite ().argc ;
8181
82- /* FreeBSD may cause a segfault :https://reviews.freebsd.org/D5112 */
83- #ifndef P_OS_FREEBSD
8482 BOOST_CHECK (p_library_loader_new (" ." P_DIR_SEPARATOR " p_empty_file.txt" ) == NULL );
85- #endif
8683 BOOST_CHECK (p_library_loader_new (boost::unit_test::framework::master_test_suite ().argv [argCount - 1 ]) == NULL );
8784
8885#ifdef P_OS_WIN
You can’t perform that action at this time.
0 commit comments