mirror of
https://github.com/Cisco-Talos/clamav.git
synced 2025-10-19 10:23:17 +00:00
Windows: improved support for '/' path separators
The new Sigtool feature tests are failing on Windows because CMake is providing the CVD_CERTS_DIR environment variable with '/' path separators. My fix is to convert '/' to '\\' when converting paths to UNC paths. I have also changed CMake to provide CVD_CERTS_DIR with native paths. I also made a couple of fixes to the Sigtool tests because Windows wants to make CRLF line endings in Python unless you write byte-strings and Sigtool will get upset when making a diff if a signature file contains CRLF line endings. And putting Windows path separators into 'verify_output()' for the tests gets confused because it is actually a regex string and the backslashes mess it up.
This commit is contained in:
parent
c0eb5d52dc
commit
9208d26b66
3 changed files with 23 additions and 10 deletions
|
@ -148,6 +148,8 @@ if(LLVM_FOUND)
|
|||
list(JOIN LLVM_LIBRARY_DIRS "," LLVM_DIRS)
|
||||
endif()
|
||||
|
||||
set(CVD_CERTS_DIR ${CMAKE_SOURCE_DIR}/unit_tests/input/signing/verify)
|
||||
|
||||
if(WIN32)
|
||||
file(TO_NATIVE_PATH ${CMAKE_SOURCE_DIR} SOURCE)
|
||||
file(TO_NATIVE_PATH ${CMAKE_BINARY_DIR} BUILD)
|
||||
|
@ -194,6 +196,9 @@ if(WIN32)
|
|||
file(TO_NATIVE_PATH $<TARGET_FILE_DIR:check_clamav>/freshclam.exe FRESHCLAM)
|
||||
file(TO_NATIVE_PATH $<TARGET_FILE_DIR:check_clamav>/sigtool.exe SIGTOOL)
|
||||
endif()
|
||||
|
||||
# Convert the CVD_CERTS_DIR to a native path for Windows (replacing forward slashes with backslashes).
|
||||
file(TO_NATIVE_PATH ${CVD_CERTS_DIR} CVD_CERTS_DIR)
|
||||
else()
|
||||
set(LD_LIBRARY_PATH $<TARGET_FILE_DIR:ClamAV::libclamav>:$<TARGET_FILE_DIR:${LIBMSPACK}>:$ENV{LD_LIBRARY_PATH})
|
||||
if(NOT ENABLE_LIBCLAMAV_ONLY)
|
||||
|
@ -264,7 +269,7 @@ set(ENVIRONMENT
|
|||
CK_DEFAULT_TIMEOUT=300
|
||||
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
|
||||
DYLD_LIBRARY_PATH=${LD_LIBRARY_PATH}
|
||||
CVD_CERTS_DIR=${CMAKE_SOURCE_DIR}/unit_tests/input/signing/verify
|
||||
CVD_CERTS_DIR=${CVD_CERTS_DIR}
|
||||
PATH=${NEW_PATH}
|
||||
LIBSSL=${LIBSSL}
|
||||
LIBCRYPTO=${LIBCRYPTO}
|
||||
|
|
|
@ -250,7 +250,7 @@ class TC(testcase.TestCase):
|
|||
|
||||
expected_results = [
|
||||
'Generated diff file',
|
||||
"correctly applies to {}".format(TC.path_tmp / 'test-5.cvd'),
|
||||
'correctly applies to',
|
||||
]
|
||||
self.verify_output(output.out, expected=expected_results)
|
||||
|
||||
|
@ -285,9 +285,9 @@ class TC(testcase.TestCase):
|
|||
self.verify_output(output.err, expected=expected_results)
|
||||
|
||||
# Add a line to one of the signature files.
|
||||
with (TC.path_tmp / 'test.ldb').open('a') as f:
|
||||
with (TC.path_tmp / 'test.ldb').open('ab') as f:
|
||||
f.write(
|
||||
'What.a.Silly.Sig.Name-123-0;Engine:51-255,Target:0;0;deadbeefcafe\n'
|
||||
b'What.a.Silly.Sig.Name-123-0;Engine:51-255,Target:0;0;deadbeefcafe\n'
|
||||
)
|
||||
|
||||
# Set 'SIGNDUSER' environment variable to 'pytest' to avoid permission issues.
|
||||
|
@ -307,9 +307,8 @@ class TC(testcase.TestCase):
|
|||
'New sigs: 28',
|
||||
'Created test.cud',
|
||||
'Generated diff file test-7.script',
|
||||
"Verification: {path_tmp}/test-7.script correctly applies to the previous version".format(
|
||||
path_tmp=TC.path_tmp
|
||||
),
|
||||
'Verification',
|
||||
'test-7.script correctly applies to the previous version',
|
||||
]
|
||||
self.verify_output(output.out, expected=expected_results)
|
||||
|
||||
|
|
|
@ -42,12 +42,20 @@ static int is_abspath(const char *path)
|
|||
wchar_t *uncpath(const char *path)
|
||||
{
|
||||
DWORD len = 0;
|
||||
size_t i;
|
||||
char fix_path_seps[PATH_MAX + 1] = {0};
|
||||
char utf8[PATH_MAX + 1];
|
||||
wchar_t *stripme, *strip_from, *dest = malloc((PATH_MAX + 1) * sizeof(wchar_t));
|
||||
|
||||
if (!dest)
|
||||
return NULL;
|
||||
|
||||
// Fix path separators
|
||||
for (i = 0; i < strlen(path); i++) {
|
||||
fix_path_seps[i] = (path[i] == '/') ? '\\' : path[i];
|
||||
}
|
||||
path = fix_path_seps;
|
||||
|
||||
if (strncmp(path, "\\\\", 2)) {
|
||||
/* NOT already UNC */
|
||||
memcpy(dest, L"\\\\?\\", 8);
|
||||
|
@ -60,9 +68,9 @@ wchar_t *uncpath(const char *path)
|
|||
errno = (len || (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) ? ENAMETOOLONG : ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
if (*path == '\\')
|
||||
if (*path == '\\') {
|
||||
len = 6; /* Current drive root */
|
||||
else {
|
||||
} else {
|
||||
len += 4; /* A 'really' relative path */
|
||||
dest[len] = L'\\';
|
||||
len++;
|
||||
|
@ -105,8 +113,9 @@ wchar_t *uncpath(const char *path)
|
|||
*stripme = L'\0';
|
||||
copy_from = &stripme[3];
|
||||
copy_to = wcsrchr(strip_from, L'\\');
|
||||
if (!copy_to)
|
||||
if (!copy_to) {
|
||||
copy_to = stripme;
|
||||
}
|
||||
} else {
|
||||
strip_from = &stripme[1];
|
||||
continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue