Skip to content

Commit baa1e87

Browse files
committed
Check error code in rust_file_is_dir. Prevent comparison of uninitialized mem
1 parent 4951bb8 commit baa1e87

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/rt/rust_builtin.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,9 @@ rust_dirent_filename(rust_task *task, dirent* ent) {
446446
extern "C" CDECL int
447447
rust_file_is_dir(rust_task *task, rust_str *path) {
448448
struct stat buf;
449-
stat((char*)path->data, &buf);
449+
if (stat((char*)path->data, &buf)) {
450+
return 0;
451+
}
450452
return S_ISDIR(buf.st_mode);
451453
}
452454

src/test/stdtest/fs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ fn test_connect() {
1414
#[test]
1515
fn test_list_dir_no_invalid_memory_access() { fs::list_dir(~"."); }
1616

17+
#[test]
18+
fn file_is_dir() {
19+
assert fs::file_is_dir(~".");
20+
assert !fs::file_is_dir(~"test/stdtest/fs.rs");
21+
}

0 commit comments

Comments
 (0)