Skip to content

Commit f41992d

Browse files
author
blake2-ppc
committed
---
yaml --- r: 145170 b: refs/heads/try2 c: e211888 h: refs/heads/master v: v3
1 parent f981f6c commit f41992d

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 6e538edea2557018c3c8eae41aacf6cdf6370a4d
8+
refs/heads/try2: e211888407db32fcec53f4fa9eb84acdbdf59f87
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

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