From 4b991203df4fc29dcba72e4edf132a89709c04f9 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Sun, 9 Oct 2016 00:28:22 +0200 Subject: [PATCH] pefile.cpp: make import sorting independent from qsort() internals. --- src/pefile.cpp | 4 +++- src/util.h | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pefile.cpp b/src/pefile.cpp index 0f1bce79..2f6c81f3 100644 --- a/src/pefile.cpp +++ b/src/pefile.cpp @@ -874,7 +874,9 @@ unsigned PeFile::processImports0(ord_mask_t ord_mask) // pass 1 if (u2->ordinal) return 1; if (!u1->shname) return 1; if (!u2->shname) return -1; - return strlen(u1->shname) - strlen(u2->shname); + rc = (int) (upx_strlen(u1->shname) - upx_strlen(u2->shname)); + if (rc) return rc; + return strcmp(u1->shname, u2->shname); } }; diff --git a/src/util.h b/src/util.h index 0f1aebf2..b1f20045 100644 --- a/src/util.h +++ b/src/util.h @@ -100,6 +100,10 @@ inline char *strcpy(unsigned char *s1, const unsigned char *s2) { return strcpy((char *) s1, (const char *) s2); } +inline int strcmp(const unsigned char *s1, const unsigned char *s2) { + return strcmp((const char *) s1, (const char *) s2); +} + inline int strcasecmp(const unsigned char *s1, const unsigned char *s2) { return strcasecmp((const char *) s1, (const char *) s2); }