Skip to content

Commit

Permalink
mach.segment: safely convert segment commands to unified version. fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
m4b committed Jan 28, 2018
1 parent 7774aea commit 7a8f265
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/mach/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ impl<'a> MachO<'a> {
debug!("{} - {:?}", i, cmd);
match cmd.command {
load_command::CommandVariant::Segment32(command) => {
segments.push(segment::Segment::from_32(bytes, &command, cmd.offset, ctx))
segments.push(segment::Segment::from_32(bytes, &command, cmd.offset, ctx)?)
},
load_command::CommandVariant::Segment64(command) => {
segments.push(segment::Segment::from_64(bytes, &command, cmd.offset, ctx))
segments.push(segment::Segment::from_64(bytes, &command, cmd.offset, ctx)?)
},
load_command::CommandVariant::Symtab(command) => {
symbols = Some(symbols::Symbols::parse(bytes, &command, ctx)?);
Expand Down
16 changes: 8 additions & 8 deletions src/mach/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,9 @@ impl<'a> Segment<'a> {
Ok(sections)
}
/// Convert the raw C 32-bit segment command to a generalized version
pub fn from_32(bytes: &'a[u8], segment: &SegmentCommand32, offset: usize, ctx: container::Ctx) -> Self {
let data = &bytes[segment.fileoff as usize..(segment.fileoff + segment.filesize) as usize];
Segment {
pub fn from_32(bytes: &'a[u8], segment: &SegmentCommand32, offset: usize, ctx: container::Ctx) -> Result<Self, error::Error> {
let data = bytes.pread_with(segment.fileoff as usize, segment.filesize as usize)?;
Ok(Segment {
cmd: segment.cmd,
cmdsize: segment.cmdsize,
segname: segment.segname,
Expand All @@ -437,12 +437,12 @@ impl<'a> Segment<'a> {
offset: offset,
raw_data: bytes,
ctx: ctx,
}
})
}
/// Convert the raw C 64-bit segment command to a generalized version
pub fn from_64(bytes: &'a [u8], segment: &SegmentCommand64, offset: usize, ctx: container::Ctx) -> Self {
let data = &bytes[segment.fileoff as usize..(segment.fileoff + segment.filesize) as usize];
Segment {
pub fn from_64(bytes: &'a [u8], segment: &SegmentCommand64, offset: usize, ctx: container::Ctx) -> Result<Self, error::Error> {
let data = bytes.pread_with(segment.fileoff as usize, segment.filesize as usize)?;
Ok(Segment {
cmd: segment.cmd,
cmdsize: segment.cmdsize,
segname: segment.segname,
Expand All @@ -458,7 +458,7 @@ impl<'a> Segment<'a> {
data: data,
raw_data: bytes,
ctx: ctx,
}
})
}
}

Expand Down

0 comments on commit 7a8f265

Please sign in to comment.