Check error code in rust_file_is_dir. Prevent comparison of uninitialized mem

This commit is contained in:
Brian Anderson 2011-09-01 12:38:36 -07:00
parent 4951bb8bfc
commit baa1e8790d
2 changed files with 8 additions and 1 deletions

View File

@ -446,7 +446,9 @@ rust_dirent_filename(rust_task *task, dirent* ent) {
extern "C" CDECL int extern "C" CDECL int
rust_file_is_dir(rust_task *task, rust_str *path) { rust_file_is_dir(rust_task *task, rust_str *path) {
struct stat buf; struct stat buf;
stat((char*)path->data, &buf); if (stat((char*)path->data, &buf)) {
return 0;
}
return S_ISDIR(buf.st_mode); return S_ISDIR(buf.st_mode);
} }

View File

@ -14,3 +14,8 @@ fn test_connect() {
#[test] #[test]
fn test_list_dir_no_invalid_memory_access() { fs::list_dir(~"."); } 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");
}