Browse Source

expat cross-platform fixes

Guenter Obiltschnig 9 years ago
parent
commit
da66f2863a
2 changed files with 15 additions and 6 deletions
  1. 1 1
      XML/Makefile
  2. 14 5
      XML/src/xmlparse.cpp

+ 1 - 1
XML/Makefile

@@ -8,7 +8,7 @@
 
 include $(POCO_BASE)/build/rules/global
 
-COMMONFLAGS += -DXML_NS -DXML_DTD -DHAVE_EXPAT_CONFIG_H
+COMMONFLAGS += -DXML_NS -DXML_DTD -DHAVE_EXPAT_CONFIG_H -DEXPAT_POCO
 
 objects = AbstractContainerNode AbstractNode Attr AttrMap Attributes \
 	AttributesImpl CDATASection CharacterData ChildNodesList Comment \

+ 14 - 5
XML/src/xmlparse.cpp

@@ -7,12 +7,19 @@
 #include <assert.h>
 #include <limits.h>                     /* UINT_MAX */
 
-#ifdef _WIN32
-#define getpid GetCurrentProcessId
+#define EXPAT_POCO 1
+
+#if defined(EXPAT_POCO)
+#include "Poco/Process.h"
+#include "Poco/Timestamp.h"
+#define platform_getpid Poco::Process::id
+#elif defined(_WIN32)
+#define platform_getpid GetCurrentProcessId
 #else
 #include <sys/time.h>                   /* gettimeofday() */
 #include <sys/types.h>                  /* getpid() */
 #include <unistd.h>                     /* getpid() */
+#define platform_getpid getpid
 #endif
 
 #define XML_BUILDING_EXPAT 1
@@ -703,9 +710,11 @@ static const XML_Char implicitContext[] = {
 };
 
 static unsigned long
-gather_time_entropy(void)
+platform_gather_time_entropy(void)
 {
-#ifdef WIN32
+#if defined(EXPAT_POCO)
+  return static_cast<unsigned long>(Poco::Timestamp().utcTime());
+#elif defined(_WIN32)
   FILETIME ft;
   GetSystemTimeAsFileTime(&ft); /* never fails */
   return ft.dwHighDateTime ^ ft.dwLowDateTime;
@@ -727,7 +736,7 @@ generate_hash_secret_salt(XML_Parser parser)
   /* Process ID is 0 bits entropy if attacker has local access
    * XML_Parser address is few bits of entropy if attacker has local access */
   const unsigned long entropy =
-      gather_time_entropy() ^ getpid() ^ (unsigned long)parser;
+      platform_gather_time_entropy() ^ platform_getpid() ^ (unsigned long)parser;
 
   /* Factors are 2^31-1 and 2^61-1 (Mersenne primes M31 and M61) */
   if (sizeof(unsigned long) == 4) {