Check error code in rust_file_is_dir. Prevent comparison of uninitialized mem
This commit is contained in:
parent
4951bb8bfc
commit
baa1e8790d
@ -446,7 +446,9 @@ rust_dirent_filename(rust_task *task, dirent* ent) {
|
||||
extern "C" CDECL int
|
||||
rust_file_is_dir(rust_task *task, rust_str *path) {
|
||||
struct stat buf;
|
||||
stat((char*)path->data, &buf);
|
||||
if (stat((char*)path->data, &buf)) {
|
||||
return 0;
|
||||
}
|
||||
return S_ISDIR(buf.st_mode);
|
||||
}
|
||||
|
||||
|
@ -14,3 +14,8 @@ fn test_connect() {
|
||||
#[test]
|
||||
fn test_list_dir_no_invalid_memory_access() { fs::list_dir(~"."); }
|
||||
|
||||
#[test]
|
||||
fn file_is_dir() {
|
||||
assert fs::file_is_dir(~".");
|
||||
assert !fs::file_is_dir(~"test/stdtest/fs.rs");
|
||||
}
|
Loading…
Reference in New Issue
Block a user