Skip to content

Commit 9367991

Browse files
author
blake2-ppc
committed
---
yaml --- r: 80516 b: refs/heads/master c: e211888 h: refs/heads/master v: v3
1 parent 91bc837 commit 9367991

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 6e538edea2557018c3c8eae41aacf6cdf6370a4d
2+
refs/heads/master: e211888407db32fcec53f4fa9eb84acdbdf59f87
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cbd1eefbd350797b783df119fed7956d7e1c74ad
55
refs/heads/try: 71bebebc37fbb229877da88dde13c2f35913bd77

trunk/src/libstd/at_vec.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,16 @@ pub mod raw {
230230
// Implementation detail. Shouldn't be public
231231
#[allow(missing_doc)]
232232
pub fn reserve_raw(ty: *TyDesc, ptr: *mut *mut Box<Vec<()>>, n: uint) {
233-
233+
// check for `uint` overflow
234234
unsafe {
235-
let size_in_bytes = n * (*ty).size;
236-
if size_in_bytes > (**ptr).data.alloc {
237-
let total_size = size_in_bytes + sys::size_of::<Vec<()>>();
235+
if n > (**ptr).data.alloc / (*ty).size {
236+
let alloc = n * (*ty).size;
237+
let total_size = alloc + sys::size_of::<Vec<()>>();
238+
if alloc / (*ty).size != n || total_size < alloc {
239+
fail!("vector size is too large: %u", n);
240+
}
238241
(*ptr) = local_realloc(*ptr as *(), total_size) as *mut Box<Vec<()>>;
239-
(**ptr).data.alloc = size_in_bytes;
242+
(**ptr).data.alloc = alloc;
240243
}
241244
}
242245

trunk/src/libstd/vec.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3659,6 +3659,14 @@ mod tests {
36593659
v.push(2);
36603660
}
36613661

3662+
#[test]
3663+
#[should_fail]
3664+
fn test_overflow_does_not_cause_segfault_managed() {
3665+
let mut v = ~[@1];
3666+
v.reserve(-1);
3667+
v.push(@2);
3668+
}
3669+
36623670
#[test]
36633671
fn test_mut_split() {
36643672
let mut values = [1u8,2,3,4,5];

0 commit comments

Comments
 (0)