This is an automated email from the ASF dual-hosted git repository. pengzheng pushed a commit to branch hotfix/double-dlclose in repository https://gitbox.apache.org/repos/asf/celix.git
commit 314e53276747e6dc57ae012eac2a47d33e5eabe1 Author: PengZheng <[email protected]> AuthorDate: Mon May 1 15:38:53 2023 +0800 Protect against bundles with bad exports. --- libs/framework/gtest/CMakeLists.txt | 6 +++- .../src/CelixBundleContextBundlesTestSuite.cc | 5 +++ libs/framework/src/manifest_parser.c | 9 ----- libs/framework/src/module.c | 38 ++++++++-------------- 4 files changed, 23 insertions(+), 35 deletions(-) diff --git a/libs/framework/gtest/CMakeLists.txt b/libs/framework/gtest/CMakeLists.txt index 5b035dd1..5c7e3637 100644 --- a/libs/framework/gtest/CMakeLists.txt +++ b/libs/framework/gtest/CMakeLists.txt @@ -25,6 +25,8 @@ celix_bundle_description(simple_test_bundle1 "Test Description") add_celix_bundle(simple_test_bundle2 NO_ACTIVATOR VERSION 1.0.0) add_celix_bundle(simple_test_bundle3 NO_ACTIVATOR VERSION 1.0.0) add_celix_bundle(bundle_with_exception SOURCES src/nop_activator.c VERSION 1.0.0) +add_celix_bundle(bundle_with_bad_export NO_ACTIVATOR VERSION 1.0.0) +celix_bundle_headers(bundle_with_bad_export "Export-Library: $<SEMICOLON>") add_celix_bundle(simple_cxx_bundle SOURCES src/HelloWorldCxxActivator.cc VERSION 1.0.0) celix_bundle_libs(simple_cxx_bundle "PRIVATE" TRUE Celix::framework) add_celix_bundle(simple_cxx_dep_man_bundle SOURCES src/HelloWorldCxxActivatorWithDepMan.cc VERSION 1.0.0) @@ -75,7 +77,7 @@ celix_target_bundle_set_definition(test_framework NAME BUNDLE_TEST_SET add_celix_bundle_dependencies(test_framework simple_test_bundle1 simple_test_bundle2 simple_test_bundle3 simple_test_bundle4 - simple_test_bundle5 bundle_with_exception unresolvable_bundle simple_cxx_bundle simple_cxx_dep_man_bundle cmp_test_bundle) + simple_test_bundle5 bundle_with_exception bundle_with_bad_export unresolvable_bundle simple_cxx_bundle simple_cxx_dep_man_bundle cmp_test_bundle) target_include_directories(test_framework PRIVATE ../src) celix_deprecated_utils_headers(test_framework) @@ -88,6 +90,7 @@ celix_get_bundle_filename(simple_test_bundle4 SIMPLE_TEST_BUNDLE4_FILENAME) celix_get_bundle_filename(simple_test_bundle5 SIMPLE_TEST_BUNDLE5_FILENAME) celix_get_bundle_filename(bundle_with_exception BUNDLE_WITH_EXCEPTION) +celix_get_bundle_file(bundle_with_bad_export BUNDLE_WITH_BAD_EXPORT) celix_get_bundle_filename(unresolvable_bundle UNRESOLVABLE_BUNDLE) celix_get_bundle_file(simple_cxx_bundle SIMPLE_CXX_BUNDLE_LOC) @@ -106,6 +109,7 @@ target_compile_definitions(test_framework PRIVATE SIMPLE_TEST_BUNDLE4_LOCATION="${SIMPLE_TEST_BUNDLE4_FILENAME}" SIMPLE_TEST_BUNDLE5_LOCATION="${SIMPLE_TEST_BUNDLE5_FILENAME}" TEST_BUNDLE_WITH_EXCEPTION_LOCATION="${BUNDLE_WITH_EXCEPTION}" + BUNDLE_WITH_BAD_EXPORT_LOCATION="${BUNDLE_WITH_BAD_EXPORT}" TEST_BUNDLE_UNRESOLVABLE_LOCATION="${UNRESOLVABLE_BUNDLE}" SIMPLE_CXX_BUNDLE_LOC="${SIMPLE_CXX_BUNDLE_LOC}" CMP_TEST_BUNDLE_LOC="${CMP_TEST_BUNDLE_LOC}" diff --git a/libs/framework/gtest/src/CelixBundleContextBundlesTestSuite.cc b/libs/framework/gtest/src/CelixBundleContextBundlesTestSuite.cc index 5a9e0e44..1fa35982 100644 --- a/libs/framework/gtest/src/CelixBundleContextBundlesTestSuite.cc +++ b/libs/framework/gtest/src/CelixBundleContextBundlesTestSuite.cc @@ -72,6 +72,11 @@ TEST_F(CelixBundleContextBundlesTestSuite, InstallABundleTest) { ASSERT_TRUE(bndId >= 0); } +//TEST_F(CelixBundleContextBundlesTestSuite, InstallBundleWithBadExport) { +// long bndId = celix_bundleContext_installBundle(ctx, BUNDLE_WITH_BAD_EXPORT_LOCATION, true); +// ASSERT_TRUE(bndId >= 0); +//} + TEST_F(CelixBundleContextBundlesTestSuite, InstallBundlesTest) { long bndId = celix_bundleContext_installBundle(ctx, "non-existing.zip", true); ASSERT_TRUE(bndId < 0); diff --git a/libs/framework/src/manifest_parser.c b/libs/framework/src/manifest_parser.c index 038af09b..d53d42c7 100644 --- a/libs/framework/src/manifest_parser.c +++ b/libs/framework/src/manifest_parser.c @@ -389,11 +389,6 @@ static linked_list_pt manifestParser_parseImportHeader(const char * header) { linkedList_destroy(clauses); - if(failure){ - linkedList_destroy(requirements); - requirements = NULL; - } - return requirements; } @@ -450,10 +445,6 @@ static linked_list_pt manifestParser_parseExportHeader(module_pt module, const c } linkedList_destroy(clauses); - if(failure){ - linkedList_destroy(capabilities); - capabilities = NULL; - } return capabilities; } diff --git a/libs/framework/src/module.c b/libs/framework/src/module.c index 71192e57..0c35462f 100644 --- a/libs/framework/src/module.c +++ b/libs/framework/src/module.c @@ -420,43 +420,31 @@ static celix_status_t celix_module_loadLibraryForManifestEntry(celix_module_t* m static celix_status_t celix_module_loadLibrariesInManifestEntry(celix_module_t* module, const char *librariesIn, const char *activator, bundle_archive_pt archive, void **activatorHandle) { celix_status_t status = CELIX_SUCCESS; - char* last; char* libraries = strndup(librariesIn, 1024*10); - char* token = strtok_r(libraries, ",", &last); - while (token != NULL && status == CELIX_SUCCESS) { + + char* saveptr1; + for (char* str1 = libraries; status == CELIX_SUCCESS; str1 = NULL) { + char* token = strtok_r(str1, ",", &saveptr1); + char* saveptr2; + if (token == NULL) { + break; + } + char *pathToken = strtok_r(token, ";", &saveptr2); + if (pathToken == NULL) { + continue; + } + void *handle = NULL; char lib[128]; lib[127] = '\0'; - - char *path = NULL; - char *pathToken = strtok_r(token, ";", &path); strncpy(lib, pathToken, 127); - pathToken = strtok_r(NULL, ";", &path); - - while (pathToken != NULL) { - - /*Disable version should be part of the lib name - if (strncmp(pathToken, "version", 7) == 0) { - char *ver = strdup(pathToken); - char version[strlen(ver) - 9]; - strncpy(version, ver+9, strlen(ver) - 10); - version[strlen(ver) - 10] = '\0'; - - strcat(lib, "-"); - strcat(lib, version); - }*/ - pathToken = strtok_r(NULL, ";", &path); - } - char *trimmedLib = utils_stringTrim(lib); status = celix_module_loadLibraryForManifestEntry(module, trimmedLib, archive, &handle); if ( (status == CELIX_SUCCESS) && (activator != NULL) && (strcmp(trimmedLib, activator) == 0) ) { *activatorHandle = handle; } - token = strtok_r(NULL, ",", &last); } - free(libraries); return status; }
