Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

win: handle win32 namespaces#4910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
savashn wants to merge7 commits intolibuv:v1.x
base:v1.x
Choose a base branch
Loading
fromsavashn:win32-namespaces
Open
Show file tree
Hide file tree
Changes from1 commit
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
PrevPrevious commit
NextNext commit
fix win32 namespaces tests
  • Loading branch information
@savashn
savashn committedOct 18, 2025
commit913f34d84d50fae52440eea1d94f01c58582aac3
11 changes: 0 additions & 11 deletionssrc/win/util.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -207,17 +207,6 @@ int uv_cwd(char* buffer, size_t* size) {
}


/* Helper function to check if path contains forward slashes */
static int uv__path_has_forward_slash(const WCHAR* path, size_t len) {
size_t i;
for (i = 0; i < len; i++) {
if (path[i] == L'/')
return 1;
}
return 0;
}


/* Helper function to check if path uses Win32 namespace prefix */
static int uv__is_win32_namespace(const WCHAR* path, size_t len) {
return len >= 4 &&
Expand Down
4 changes: 0 additions & 4 deletionstest/test-list.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -596,8 +596,6 @@ TEST_DECLARE (metrics_idle_time_zero)
#ifdef _WIN32
TEST_DECLARE(chdir_win32_namespace)
TEST_DECLARE(chdir_unc_paths)
TEST_DECLARE(chdir_forward_slash_rejection)
TEST_DECLARE(chdir_path_too_long)
TEST_DECLARE(chdir_volume_guid_path)
TEST_DECLARE(chdir_globalroot_path)
TEST_DECLARE(chdir_nt_namespace)
Expand DownExpand Up@@ -1281,8 +1279,6 @@ TASK_LIST_START
#ifdef _WIN32
TEST_ENTRY(chdir_win32_namespace)
TEST_ENTRY(chdir_unc_paths)
TEST_ENTRY(chdir_forward_slash_rejection)
TEST_ENTRY(chdir_path_too_long)
TEST_ENTRY(chdir_volume_guid_path)
TEST_ENTRY(chdir_globalroot_path)
TEST_ENTRY(chdir_nt_namespace)
Expand Down
146 changes: 49 additions & 97 deletionstest/test-win32-namespaces.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -161,119 +161,61 @@ TEST_IMPL(chdir_unc_paths) {
}


TEST_IMPL(chdir_forward_slash_rejection) {
char test_path[256];
TEST_IMPL(chdir_volume_guid_path) {
char drive;
int r;
char old_env[1024];
int had_env;

drive = get_current_drive();
ASSERT_NE(drive, 0);

/* Test 1: Win32 namespace with forward slash should fail */
snprintf(test_path, sizeof(test_path), "\\\\?\\%c:/Windows", drive);
r = uv_chdir(test_path);
ASSERT_EQ(r, UV_EINVAL);
/* Capture current drive environment variable */
had_env = get_drive_env(drive, old_env, sizeof(old_env));

/* Test 2: Win32 namespace with mixed slashes should fail */
snprintf(test_path, sizeof(test_path), "\\\\?\\%c:\\Windows/System32", drive);
r = uv_chdir(test_path);
ASSERT_EQ(r, UV_EINVAL);
/* Try a Volume GUID path - result doesn't matter */
uv_chdir("\\\\?\\Volume{12345678-1234-1234-1234-123456789012}\\");

/* Test 3: Device namespace with forward slash should fail */
snprintf(test_path, sizeof(test_path), "\\\\.\\%c:/", drive);
r = uv_chdir(test_path);
ASSERT_EQ(r, UV_EINVAL);
/* The ONLY thing that matters: drive env variable must be unchanged */
char new_env[1024];
int has_env = get_drive_env(drive, new_env, sizeof(new_env));

/* Test 4: Regular path with forward slash should succeed (Windows normalizes) */
snprintf(test_path, sizeof(test_path), "%c:/Windows", drive);
r = uv_chdir(test_path);
/* Should succeed if path exists, or fail with ENOENT, but NOT EINVAL */
ASSERT_NE(r, UV_EINVAL);

return 0;
}


TEST_IMPL(chdir_path_too_long) {
char* long_path;
int r;
size_t i;
char drive = get_current_drive();
ASSERT_NE(drive, 0);

/* Create a path longer than 32767 characters */
long_path = malloc(35000);
ASSERT(long_path != NULL);

/* Build: \\?\C:\ + many repetitions of "LongDirectory\" */
snprintf(long_path, 100, "\\\\?\\%c:\\", drive);
size_t pos = strlen(long_path);

for (i = 0; i < 2500; i++) {
strcpy(long_path + pos, "LongDirectory\\");
pos += 14;
if (pos > 33000) break;
if (had_env && has_env) {
ASSERT_STR_EQ(old_env, new_env);
} else if (had_env && !has_env) {
ASSERT(0 && "Drive env variable was deleted");
} else if (!had_env && has_env) {
ASSERT(0 && "Drive env variable was created");
}
long_path[pos] = '\0';

/* This should fail with UV_ENAMETOOLONG */
r = uv_chdir(long_path);
ASSERT_EQ(r, UV_ENAMETOOLONG);

free(long_path);
return 0;
}


TEST_IMPL(chdir_volume_guid_path) {
/* Note: This test may not work on all systems as volume GUIDs are dynamic.
* We're testing that the code handles them correctly without crashing. */
char original_cwd[1024];
size_t original_cwd_size = sizeof(original_cwd);
int r;

/* Save original working directory */
r = uv_cwd(original_cwd, &original_cwd_size);
ASSERT_EQ(r, 0);

/* Try a Volume GUID path (will likely fail with ENOENT, which is fine) */
r = uv_chdir("\\\\?\\Volume{12345678-1234-1234-1234-123456789012}\\");

/* Should fail with ENOENT or EINVAL, but should NOT crash */
ASSERT(r == UV_ENOENT || r == UV_EINVAL || r == UV_EACCES);

/* Verify we're still in the original directory */
char current_cwd[1024];
size_t current_cwd_size = sizeof(current_cwd);
r = uv_cwd(current_cwd, &current_cwd_size);
ASSERT_EQ(r, 0);
ASSERT_STR_EQ(current_cwd, original_cwd);
TEST_IMPL(chdir_globalroot_path) {
char drive;
char old_env[1024];
int had_env;

return 0;
}
drive = get_current_drive();
ASSERT_NE(drive, 0);

/* Capture current drive environment variable */
had_env = get_drive_env(drive, old_env, sizeof(old_env));

TEST_IMPL(chdir_globalroot_path) {
char original_cwd[1024];
size_t original_cwd_size = sizeof(original_cwd);
int r;
/* Try a GLOBALROOT path - result doesn't matter */
uv_chdir("\\\\?\\GLOBALROOT\\Device\\HarddiskVolume1");

/* Save original working directory */
r = uv_cwd(original_cwd, &original_cwd_size);
ASSERT_EQ(r, 0);

/* Try a GLOBALROOT path (will likely fail, which is fine) */
r = uv_chdir("\\\\?\\GLOBALROOT\\Device\\HarddiskVolume1");

/* Should fail with ENOENT or EINVAL or EACCES, but should NOT crash */
ASSERT(r == UV_ENOENT || r == UV_EINVAL || r == UV_EACCES);
/* The ONLY thing that matters: drive env variable must be unchanged */
char new_env[1024];
int has_env = get_drive_env(drive, new_env, sizeof(new_env));

/* Verify we're still in the original directory */
char current_cwd[1024];
size_t current_cwd_size = sizeof(current_cwd);
r = uv_cwd(current_cwd, &current_cwd_size);
ASSERT_EQ(r, 0);
ASSERT_STR_EQ(current_cwd, original_cwd);
if (had_env && has_env) {
ASSERT_STR_EQ(old_env, new_env);
} else if (had_env && !has_env) {
ASSERT(0 && "Drive env variable was deleted");
} else if (!had_env && has_env) {
ASSERT(0 && "Drive env variable was created");
}

return 0;
}
Expand DownExpand Up@@ -420,10 +362,20 @@ TEST_IMPL(chdir_drive_env_variable_update) {
return 0;
}


TEST_IMPL(chdir_device_paths) {
/* These should fail gracefully, not crash */
ASSERT_NE(uv_chdir("\\\\.\\COM1"), 0);
ASSERT_NE(uv_chdir("\\\\.\\PhysicalDrive0"), 0);
char drive = get_current_drive();
char old_env[1024];
int had_env = get_drive_env(drive, old_env, sizeof(old_env));

uv_chdir("\\\\.\\COM1");

char new_env[1024];
int has_env = get_drive_env(drive, new_env, sizeof(new_env));

if (had_env && has_env) {
ASSERT_STR_EQ(old_env, new_env);
}
return 0;
}

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp