diff options
| author | Brian Anderson <banderson@mozilla.com> | 2011-07-19 16:55:09 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-07-19 16:55:45 -0700 |
| commit | 652214d7f90516fd77394fddd65cda69d8861e58 (patch) | |
| tree | d85ff2477e092812b07238c33ff70deaedc8b5da | |
| parent | 19a17b3d1d0d25155c8bd11c73bf88238f9bd180 (diff) | |
| download | rust-652214d7f90516fd77394fddd65cda69d8861e58.tar.gz rust-652214d7f90516fd77394fddd65cda69d8861e58.zip | |
Fix calculation of sizeof boxed ivec of str in rt. Closes #712
| -rw-r--r-- | src/rt/rust_builtin.cpp | 6 | ||||
| -rw-r--r-- | src/rt/rust_util.h | 1 | ||||
| -rw-r--r-- | src/test/run-pass/lib-fs.rs | 10 |
3 files changed, 15 insertions, 2 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index df7b1cfc6d3..e434138f102 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -608,8 +608,12 @@ rust_list_files_ivec(rust_task *task, rust_str *path) { closedir(dirp); } #endif + size_t str_ivec_sz = + sizeof(size_t) // fill + + sizeof(size_t) // alloc + + sizeof(rust_str *) * 4; // payload rust_box *box = (rust_box *)task->malloc(sizeof(rust_box) + - sizeof(rust_ivec)); + str_ivec_sz); box->ref_count = 1; rust_ivec *iv = (rust_ivec *)&box->data; iv->fill = 0; diff --git a/src/rt/rust_util.h b/src/rt/rust_util.h index cf0e4ea20c9..99db357658e 100644 --- a/src/rt/rust_util.h +++ b/src/rt/rust_util.h @@ -202,6 +202,7 @@ rust_ivec_heap uint8_t data[]; }; +// Note that the payload is actually size 4*sizeof(elem), even when heapified union rust_ivec_payload { diff --git a/src/test/run-pass/lib-fs.rs b/src/test/run-pass/lib-fs.rs index eb57402168f..8bc8989e563 100644 --- a/src/test/run-pass/lib-fs.rs +++ b/src/test/run-pass/lib-fs.rs @@ -9,4 +9,12 @@ fn test_connect() { assert (fs::connect("a" + slash, "b") == "a" + slash + "b"); } -fn main() { test_connect(); } \ No newline at end of file +// Issue #712 +fn test_list_dir_no_invalid_memory_access() { + fs::list_dir("."); +} + +fn main() { + test_connect(); + test_list_dir_no_invalid_memory_access(); +} \ No newline at end of file |
