Skip to content

Commit 9865cbe

Browse files
authored
Fix NUL byte crash in resolver (#9640)
1 parent 4cd9467 commit 9865cbe

File tree

1 file changed

+6
-9
lines changed
  • packages/utils/node-resolver-rs/src

1 file changed

+6
-9
lines changed

packages/utils/node-resolver-rs/src/path.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn canonicalize(
6969
let mut seen_links = 0;
7070
let mut queue = VecDeque::new();
7171

72-
queue.push_back(path);
72+
queue.push_back(path.to_path_buf());
7373

7474
while let Some(cur_path) = queue.pop_front() {
7575
let mut components = cur_path.components();
@@ -87,11 +87,9 @@ pub fn canonicalize(
8787
ret.push(c);
8888

8989
// First, check the cache for the path up to this point.
90-
let link: &Path = if let Some(cached) = cache.get(&ret) {
90+
let link = if let Some(cached) = cache.get(&ret) {
9191
if let Some(link) = &*cached {
92-
// SAFETY: Keys are never removed from the cache or mutated
93-
// and PathBuf has a stable address for path data even when moved.
94-
unsafe { &*(link.as_path() as *const _) }
92+
link.clone()
9593
} else {
9694
continue;
9795
}
@@ -103,9 +101,8 @@ pub fn canonicalize(
103101
}
104102

105103
let link = std::fs::read_link(&ret)?;
106-
let ptr = unsafe { &*(link.as_path() as *const _) };
107-
cache.insert(ret.clone(), Some(link));
108-
ptr
104+
cache.insert(ret.clone(), Some(link.clone()));
105+
link
109106
};
110107

111108
seen_links += 1;
@@ -127,7 +124,7 @@ pub fn canonicalize(
127124

128125
let remaining = components.as_path();
129126
if !remaining.as_os_str().is_empty() {
130-
queue.push_front(remaining);
127+
queue.push_front(remaining.to_path_buf());
131128
}
132129
queue.push_front(link);
133130
break;

0 commit comments

Comments
 (0)