diff --git a/src/coreload/common/pal.h b/src/coreload/common/pal.h index ee16927..bdc1fae 100644 --- a/src/coreload/common/pal.h +++ b/src/coreload/common/pal.h @@ -81,6 +81,7 @@ namespace coreload pal::string_t to_lower(const pal::string_t& in); inline size_t strlen(const char_t* str) { return ::wcslen(str); } + inline size_t strnlen(const char_t* str, size_t max_size) { return ::wcsnlen(str, max_size); } inline errno_t file_open(const pal::string_t& path, const char_t* mode, FILE* stream) { return ::_wfopen_s(&stream, path.c_str(), mode); } inline void file_vprintf(FILE* f, const char_t* format, va_list vl) { ::vfwprintf(f, format, vl); ::fputwc(_X('\n'), f); } inline void err_fputs(const char_t* message) { ::fputws(message, stderr); ::fputwc(_X('\n'), stderr); } diff --git a/src/coreload/dll/coreload.cc b/src/coreload/dll/coreload.cc index 64f4917..ff0e174 100644 --- a/src/coreload/dll/coreload.cc +++ b/src/coreload/dll/coreload.cc @@ -6,7 +6,7 @@ int ValidateArgument( { if (argument != nullptr) { - const size_t string_length = pal::strlen(argument); + const size_t string_length = pal::strnlen(argument, max_size); if (string_length == 0 || string_length >= max_size) { return StatusCode::InvalidArgFailure;