From d266c6bff137dc326d326b0be4268b808a80100e Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Wed, 13 Dec 2000 15:04:53 +0000 Subject: [PATCH] Added Packer::getLoaderSectionStart(), where the size of the section is allowed to be zero. committer: mfx 976719893 +0000 --- src/p_vmlinz.cpp | 2 +- src/packer.cpp | 29 +++++++++++++++++++++++------ src/packer.h | 6 ++++-- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/p_vmlinz.cpp b/src/p_vmlinz.cpp index 918d567f..6d2efb19 100644 --- a/src/p_vmlinz.cpp +++ b/src/p_vmlinz.cpp @@ -156,7 +156,7 @@ void PackvmlinuzI386::pack(OutputFile *fo) MemBuffer loader(lsize); memcpy(loader, getLoader(), lsize); - int e_len = bzImage ? getLoaderSection("LZCUTPOI") : lsize; + int e_len = bzImage ? getLoaderSectionStart("LZCUTPOI") : lsize; patchPackHeader(loader, lsize); if (bzImage) diff --git a/src/packer.cpp b/src/packer.cpp index 62586310..293a3860 100644 --- a/src/packer.cpp +++ b/src/packer.cpp @@ -42,7 +42,7 @@ Packer::Packer(InputFile *f) : fi(f), file_size(-1), ph_format(-1), ph_version(-1), uip(NULL), ui_pass(0), ui_total_passes(0), linker(NULL), - last_patch(NULL), last_patch_offset(0) + last_patch(NULL), last_patch_len(0), last_patch_off(0) { file_size = f->st.st_size; uip = new UiPacker(this); @@ -642,22 +642,28 @@ void Packer::checkPatch(void *b, int blen, int boff, int size) { // reset last_patch = NULL; - last_patch_offset = 0; + last_patch_len = 0; + last_patch_off = 0; return; } if (b == NULL || blen <= 0 || boff < 0 || size <= 0) throwBadLoader(); if (boff + size <= 0 || boff + size > blen) throwBadLoader(); - //printf("checkPatch: %p %5d %5d %d\n", b, blen, boff, size); + //printf("checkPatch: %p %5d %5d %2d\n", b, blen, boff, size); if (b == last_patch) { - if (boff + size > last_patch_offset) + if (boff + size > last_patch_off) throwInternalError("invalid patch order"); + // The next check is not strictly necessary, but the buffer + // length should better not increase... + if (blen > last_patch_len) + throwInternalError("invalid patch order (length)"); } else last_patch = b; - last_patch_offset = boff; + last_patch_len = blen; + last_patch_off = boff; } @@ -916,7 +922,7 @@ void Packer::addSection(const char *sname, const char *sdata, unsigned len) } -int Packer::getLoaderSection(const char *name, int *slen) +int Packer::getLoaderSection(const char *name, int *slen) const { int size = -1; int ostart = linker->getSection(name, &size); @@ -928,6 +934,17 @@ int Packer::getLoaderSection(const char *name, int *slen) } +// same, but the size of the section may be == 0 +int Packer::getLoaderSectionStart(const char *name) const +{ + int size = -1; + int ostart = linker->getSection(name, &size); + if (ostart < 0 || size < 0) + throwBadLoader(); + return ostart; +} + + const upx_byte *Packer::getLoader() const { int size = -1; diff --git a/src/packer.h b/src/packer.h index b25a3ea7..0a03e600 100644 --- a/src/packer.h +++ b/src/packer.h @@ -199,7 +199,8 @@ protected: virtual void initLoader(const void *pdata, int plen, int pinfo=-1); virtual void addLoader(const char *s, ...); virtual void addSection(const char *sname, const char *sdata, unsigned len); - virtual int getLoaderSection(const char *name, int *slen = NULL); + virtual int getLoaderSection(const char *name, int *slen=NULL) const; + virtual int getLoaderSectionStart(const char *name) const; virtual void addFilter32(int filter_id); virtual const char *getDecompressor() const; @@ -253,7 +254,8 @@ private: private: // private to checkPatch() void *last_patch; - int last_patch_offset; + int last_patch_len; + int last_patch_off; private: // disable copy and assignment