Skip to content

Commit 2223ee4

Browse files
author
blake2-ppc
committed
---
yaml --- r: 80596 b: refs/heads/auto c: e211888 h: refs/heads/master v: v3
1 parent 1e1b2fe commit 2223ee4

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
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 6e538edea2557018c3c8eae41aacf6cdf6370a4d
16+
refs/heads/auto: e211888407db32fcec53f4fa9eb84acdbdf59f87
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/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

branches/auto/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)