diff --git a/src/win/fs.c b/src/win/fs.c index b9b9f3a39..6d7acfd0d 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -677,7 +677,7 @@ struct path { // Must be freed by `uv__path_free`. int uv__path_init(struct path * p) { - WCHAR * buf = uv__malloc(1); + WCHAR * buf = uv__malloc(sizeof(WCHAR)); if (buf == NULL) return UV_ENOMEM; p->buf = buf; @@ -738,9 +738,11 @@ int uv__path_push(struct path * p, WCHAR * component) { } int uv__path_pop(struct path * p) { + int i; + if (p->len == 0) return 1; - for (int i = p->len - 1; i >= 0; i--) { + for (i = p->len - 1; i >= 0; i--) { if (p->buf[i] == L'\\' || i == 0) { p->buf[i] = L'\0'; p->len = i; @@ -761,15 +763,16 @@ void fs__openat(uv_fs_t* req) { UNICODE_STRING str; IO_STATUS_BLOCK isb; OBJECT_ATTRIBUTES obj; - int fd, current_umask; + int fd, current_umask, temp_umask = 0; int flags = req->fs.info.file_flags; struct uv__fd_info_s fd_info; WCHAR * path = req->file.pathw; struct path rebuilt_path; - const size_t path_len = wcslen(path); + + int i; // NtCreateFile doesn't recognize forward slashes, only back slashes. - for (int i = 0; path[i] != 0; i++) + for (i = 0; path[i] != L'\0'; i++) if (path[i] == L'/') path[i] = L'\\'; @@ -813,7 +816,7 @@ void fs__openat(uv_fs_t* req) { ) { uv__free(dir_path_buf); SET_REQ_UV_ERROR(req, UV_EBADF, ERROR_INVALID_HANDLE); - return -1; + return; } // We'll call `NtCreateFile` with an absolute path, set root dir handle @@ -860,8 +863,8 @@ void fs__openat(uv_fs_t* req) { /* Obtain the active umask. umask() never fails and returns the previous * umask. */ - current_umask = _umask(0); - _umask(current_umask); + _umask_s(temp_umask, ¤t_umask); + _umask_s(current_umask, &temp_umask); /* convert flags and mode to CreateFile parameters */ switch (flags & (UV_FS_O_RDONLY | UV_FS_O_WRONLY | UV_FS_O_RDWR)) { diff --git a/test/test-fs.c b/test/test-fs.c index e05499404..c7fa667ef 100644 --- a/test/test-fs.c +++ b/test/test-fs.c @@ -3254,6 +3254,7 @@ TEST_IMPL(fs_openat) { unlink("test/fixtures/test_dir/test_file"); unlink("test/fixtures/test_dir/link"); unlink("test/fixtures/test_dir/nested_dir/file"); + unlink("test/fixtures/file"); rmdir("test/fixtures/test_dir/nested_dir"); rmdir("test/fixtures/test_dir"); @@ -3381,7 +3382,7 @@ TEST_IMPL(fs_openat) { r = uv_fs_openat(NULL, &req, dir, - "../empty_file", + "../file", UV_FS_O_RDWR | UV_FS_O_CREAT, S_IWUSR | S_IRUSR, NULL); @@ -3398,7 +3399,7 @@ TEST_IMPL(fs_openat) { r = uv_fs_openat(NULL, &req, dir, - "../test_dir/nested_dir/././../../empty_file", + "../test_dir/nested_dir/././../../file", UV_FS_O_RDWR | UV_FS_O_CREAT, S_IWUSR | S_IRUSR, NULL); @@ -3495,6 +3496,7 @@ TEST_IMPL(fs_openat) { unlink("test/fixtures/test_dir/test_file"); unlink("test/fixtures/test_dir/link"); unlink("test/fixtures/test_dir/nested_dir/file"); + unlink("test/fixtures/file"); rmdir("test/fixtures/test_dir/nested_dir"); rmdir("test/fixtures/test_dir");