Skip to content

Commit

Permalink
write: fix reserving empty section error
Browse files Browse the repository at this point in the history
if we copy a elf with a empty section and the sh_addralign is not 0,
it will return a unaligned offset.

Signed-off-by: lzwycc <lzw32321226@163.com>
  • Loading branch information
lzw3232 committed Feb 17, 2023
1 parent a3706b5 commit 476adb1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/write/elf/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,19 @@ impl<'a> Writer<'a> {
///
/// Returns the aligned offset of the start of the range.
pub fn reserve(&mut self, len: usize, align_start: usize) -> usize {
if len == 0 {
return self.len;
if align_start > 1 {
self.len = util::align(self.len, align_start);
}
self.len = util::align(self.len, align_start);
let offset = self.len;
self.len += len;
offset
}

/// Write alignment padding bytes.
pub fn write_align(&mut self, align_start: usize) {
util::write_align(self.buffer, align_start);
if align_start > 1 {
util::write_align(self.buffer, align_start);
}
}

/// Write data.
Expand Down

0 comments on commit 476adb1

Please sign in to comment.