Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/loaders/cs_loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ loader_configuartion_end_development()

# Install
loader_configuration_begin(cs_loader "${CS_LOADER_CONFIG_TEMPLATE}")
set(DOTNET_CORE_LOADER_ASSEMBLY_PATH ${PROJECT_OUTPUT_DIR}/CSLoader.dll)
set(DOTNET_CORE_LOADER_ASSEMBLY_PATH ${CMAKE_INSTALL_PREFIX}/${INSTALL_LIB}/CSLoader.dll)
loader_configuartion_end_install()

#
Expand Down
23 changes: 19 additions & 4 deletions source/loaders/cs_loader/include/cs_loader/netcore_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
*/

#ifndef _NETCORELINUX_H_
#define _NETCORELINUX_H_

#include <cs_loader/netcore.h>
#include <log/log.h>

#include <dynlink/dynlink.h>

Expand Down Expand Up @@ -108,17 +109,31 @@ class netcore_linux : public netcore

bool LoadMain();

void AddFilesFromDirectoryToTpaList(std::string directory, std::string &tpaList)
bool AddFilesFromDirectoryToTpaList(std::string directory, std::string &tpaList)
{
for (auto &dirent : fs::directory_iterator(directory))
// Use the error_code overload so it can't throw an uncaught filesystem_error
std::error_code ec;
fs::directory_iterator it(directory, ec);
if (ec)
{
// Bad config directory, skip gracefully instead of std::terminate
log_write("metacall", LOG_LEVEL_ERROR, "cs_loader: skipping unreadable TPA directory '%s' (%s)",
directory.c_str(), ec.message().c_str());
return false;
}

for (const auto &dirent : it)
{
std::string path = dirent.path();

if (!path.compare(path.length() - 4, 4, ".dll"))
// Length guard avoids size_t underflow for names shorter than 4 chars
if (path.length() >= 4 && path.compare(path.length() - 4, 4, ".dll") == 0)
{
tpaList.append(path + ":");
}
}

return true;
}

public:
Expand Down
10 changes: 8 additions & 2 deletions source/loaders/cs_loader/source/netcore_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ bool netcore_linux::ConfigAssemblyName()
if (this->dotnet_loader_assembly_path[0] == '/')
{
this->managedAssemblyFullName.append(this->dotnet_loader_assembly_path);
AddFilesFromDirectoryToTpaList(dotnet_loader_assembly_directory, tpaList);
if (AddFilesFromDirectoryToTpaList(dotnet_loader_assembly_directory, tpaList) == false)
{
return false;
}
}
else
{
Expand All @@ -108,7 +111,10 @@ bool netcore_linux::ConfigAssemblyName()
this->nativeDllSearchDirs.append(":");
this->nativeDllSearchDirs.append(this->runtimePath);

AddFilesFromDirectoryToTpaList(this->runtimePath, tpaList);
if (AddFilesFromDirectoryToTpaList(this->runtimePath, tpaList) == false)
{
return false;
}

log_write("metacall", LOG_LEVEL_DEBUG, "NetCore application absolute path: %s", this->appPath);

Expand Down
2 changes: 1 addition & 1 deletion source/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ add_subdirectory(metacall_csharp_static_class_test)
# TODO:
# add_subdirectory(metacall_csharp_function_test)
# add_subdirectory(metacall_csharp_empty_configuration_test)
# add_subdirectory(metacall_csharp_invalid_configuration_test)
add_subdirectory(metacall_csharp_invalid_configuration_test)
add_subdirectory(metacall_julia_test)
add_subdirectory(metacall_java_test)
add_subdirectory(metacall_wasm_test)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ TEST_F(metacall_csharp_invalid_configuration_test, DefaultConstructor)
"\t}\n"
"}\n";

ASSERT_EQ((int)0, (int)metacall_load_from_memory("cs", sum, sizeof(sum), NULL));
ASSERT_NE((int)0, (int)metacall_load_from_memory("cs", sum, sizeof(sum), NULL));

metacall_destroy();
}