X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=src%2Flibelfu%2Fmodelops%2Freladd.c;h=6ab54e06096c24ae18e82f9c013b5ffd0a44d54b;hb=272d88460cae164fe310ba905c58e1834eb4eecd;hp=8c56d4ff7faa2af178b047598c7c74f46ae8e5db;hpb=e68a6c6cc16279c72e270daae0548ea7c0f11c6e;p=centaur.git diff --git a/src/libelfu/modelops/reladd.c b/src/libelfu/modelops/reladd.c index 8c56d4f..6ab54e0 100644 --- a/src/libelfu/modelops/reladd.c +++ b/src/libelfu/modelops/reladd.c @@ -5,6 +5,37 @@ #include +static ElfuScn* cloneScn(ElfuScn *ms) +{ + ElfuScn *newscn; + + assert(ms); + + newscn = elfu_mScnAlloc(); + if (!newscn) { + return NULL; + } + + newscn->shdr = ms->shdr; + + if (ms->databuf) { + void *newbuf = malloc(ms->shdr.sh_size); + if (!newbuf) { + ELFU_WARN("cloneScn: Could not allocate memory for new data buffer.\n"); + free(newscn); + return NULL; + } + + memcpy(newbuf, ms->databuf, ms->shdr.sh_size); + newscn->databuf = newbuf; + } + + newscn->oldptr = ms; + + return newscn; +} + + static int appendData(ElfuScn *ms, void *buf, size_t len) { char *newbuf; @@ -36,7 +67,7 @@ static ElfuScn* insertSection(ElfuElf *me, ElfuElf *mrel, ElfuScn *oldscn) ElfuPhdr *injPhdr; if (oldscn->shdr.sh_flags & SHF_ALLOC) { - newscn = elfu_mCloneScn(oldscn); + newscn = cloneScn(oldscn); if (!newscn) { return NULL; }