summaryrefslogtreecommitdiff
path: root/elfcopy/pe.c
diff options
context:
space:
mode:
Diffstat (limited to 'elfcopy/pe.c')
-rw-r--r--elfcopy/pe.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/elfcopy/pe.c b/elfcopy/pe.c
index 8deb809185534..f7fba1ae40d63 100644
--- a/elfcopy/pe.c
+++ b/elfcopy/pe.c
@@ -34,7 +34,7 @@
#include "elfcopy.h"
-ELFTC_VCSID("$Id: pe.c 3490 2016-08-31 00:12:22Z emaste $");
+ELFTC_VCSID("$Id: pe.c 3508 2016-12-27 06:19:39Z kaiwang27 $");
/* Convert ELF object to Portable Executable (PE). */
void
@@ -70,7 +70,7 @@ create_pe(struct elfcopy *ecp, int ifd, int ofd)
errx(EXIT_FAILURE, "gelf_getehdr() failed: %s",
elf_errmsg(-1));
- if (elf_getshstrndx(ecp->ein, &indx) == 0)
+ if (elf_getshstrndx(e, &indx) == 0)
errx(EXIT_FAILURE, "elf_getshstrndx() failed: %s",
elf_errmsg(-1));
@@ -124,7 +124,7 @@ create_pe(struct elfcopy *ecp, int ifd, int ofd)
(void) elf_errno();
continue;
}
- if ((name = elf_strptr(ecp->ein, indx, sh.sh_name)) ==
+ if ((name = elf_strptr(e, indx, sh.sh_name)) ==
NULL) {
warnx("elf_strptr() failed: %s", elf_errmsg(-1));
(void) elf_errno();
@@ -210,12 +210,14 @@ create_pe(struct elfcopy *ecp, int ifd, int ofd)
}
pb->pb_align = 1;
pb->pb_off = 0;
- pb->pb_size = roundup(sh.sh_size, poh.oh_filealign);
- if ((pb->pb_buf = calloc(1, pb->pb_size)) == NULL) {
- warn("calloc failed");
- continue;
+ if (sh.sh_type != SHT_NOBITS) {
+ pb->pb_size = roundup(sh.sh_size, poh.oh_filealign);
+ if ((pb->pb_buf = calloc(1, pb->pb_size)) == NULL) {
+ warn("calloc failed");
+ continue;
+ }
+ memcpy(pb->pb_buf, d->d_buf, sh.sh_size);
}
- memcpy(pb->pb_buf, d->d_buf, sh.sh_size);
}
elferr = elf_errno();
if (elferr != 0)