diff --git a/src/p_djgpp2.cpp b/src/p_djgpp2.cpp index 4cc3106b..7e807b12 100644 --- a/src/p_djgpp2.cpp +++ b/src/p_djgpp2.cpp @@ -150,24 +150,26 @@ static bool is_dlm(InputFile *fi, long coff_offset) static void handle_allegropak(InputFile *fi, OutputFile *fo) { unsigned char buf[0x4000]; - unsigned pfsize=0, ic; + int pfsize = 0; try { - fi->seek(-8,SEEK_END); - fi->readx(buf,8); - if (memcmp(buf,"slh+",4) != 0) + fi->seek(-8, SEEK_END); + fi->readx(buf, 8); + if (memcmp(buf, "slh+", 4) != 0) return; - pfsize = get_be32(buf+4); - fi->seek(-(off_t)pfsize,SEEK_END); + pfsize = get_be32_signed(buf+4); + if (pfsize <= 8 || pfsize >= fi->st.st_size) + return; + fi->seek(-pfsize, SEEK_END); } catch (const IOException&) { return; } - while (pfsize) + while (pfsize > 0) { - ic = pfsize < sizeof(buf) ? pfsize : sizeof(buf); - fi->readx(buf,ic); - fo->write(buf,ic); - pfsize -= ic; + const int len = UPX_MIN(pfsize, (int)sizeof(buf)); + fi->readx(buf, len); + fo->write(buf, len); + pfsize -= len; } } diff --git a/src/p_tmt.cpp b/src/p_tmt.cpp index f8ca4305..3d00a551 100644 --- a/src/p_tmt.cpp +++ b/src/p_tmt.cpp @@ -280,7 +280,7 @@ void PackTmt::pack(OutputFile *fo) int PackTmt::canUnpack() { - if (!PackTmt::readFileHeader()) + if (!readFileHeader()) return false; fi->seek(adam_offset, SEEK_SET); return readPackHeader(512) ? 1 : -1; diff --git a/src/p_w32pe.cpp b/src/p_w32pe.cpp index 7f94198c..b56245de 100644 --- a/src/p_w32pe.cpp +++ b/src/p_w32pe.cpp @@ -323,7 +323,8 @@ public: void finish(upx_byte *&p,unsigned &size); }; -Reloc::Reloc(upx_byte *s,unsigned si) : start(s), size(si), rel(0) +Reloc::Reloc(upx_byte *s,unsigned si) : + start(s), size(si), rel(NULL), rel1(NULL) { COMPILE_TIME_ASSERT(sizeof(reloc) == 8); memset(counts,0,sizeof(counts)); @@ -332,7 +333,8 @@ Reloc::Reloc(upx_byte *s,unsigned si) : start(s), size(si), rel(0) counts[type]++; } -Reloc::Reloc(unsigned rnum) : rel(0) +Reloc::Reloc(unsigned rnum) : + start(NULL), size(0), rel(NULL), rel1(NULL) { start = new upx_byte[rnum * 4 + 8192]; counts[0] = 0; @@ -790,8 +792,8 @@ private: Export::Export(char *_base) : base(_base), iv(_base) { COMPILE_TIME_ASSERT(sizeof(export_dir_t) == 40); - ename = functionptrs = ordinals = 0; - names = 0; + ename = functionptrs = ordinals = NULL; + names = NULL; memset(&edir,0,sizeof(edir)); size = 0; } @@ -1090,7 +1092,7 @@ class Resource void destroy(upx_rnode *urd,unsigned level); public: - Resource() : root(0) {} + Resource() : root(NULL) {} Resource(const upx_byte *p) {init(p);} ~Resource() {if (root) destroy (root,0);} void init(const upx_byte *); @@ -1107,7 +1109,7 @@ public: upx_byte *build(); bool clear(); - void dump() const {dump (root,0);} + void dump() const { dump(root,0); } /* unsigned iname() const {return current->parent->id;} const upx_byte *nname() const {return current->parent->name;}