bpo-30947: Update libexpat from 2.2.1 to 2.2.3 (#3106) · python/cpython@93d0cb5 · GitHub
Skip to content

Commit 93d0cb5

Browse files
authored
bpo-30947: Update libexpat from 2.2.1 to 2.2.3 (#3106)
* bpo-30947: Update libexpat from 2.2.1 to 2.2.3 * Add NEWS entry * Add new loadlibrary.c * expat_external.h: restore include "pyexpatns.h" * PCbuild: add expat/loadlibrary.c * Define XML_POOR_ENTROPY to compile expat
1 parent c99d41f commit 93d0cb5

13 files changed

Lines changed: 734 additions & 103 deletions
Lines changed: 2 additions & 0 deletions

Modules/expat/expat.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ extern "C" {
2424
struct XML_ParserStruct;
2525
typedef struct XML_ParserStruct *XML_Parser;
2626

27-
/* Should this be defined using stdbool.h when C99 is available? */
2827
typedef unsigned char XML_Bool;
2928
#define XML_TRUE ((XML_Bool) 1)
3029
#define XML_FALSE ((XML_Bool) 0)
@@ -1049,7 +1048,7 @@ XML_GetFeatureList(void);
10491048
*/
10501049
#define XML_MAJOR_VERSION 2
10511050
#define XML_MINOR_VERSION 2
1052-
#define XML_MICRO_VERSION 1
1051+
#define XML_MICRO_VERSION 3
10531052

10541053
#ifdef __cplusplus
10551054
}

Modules/expat/loadlibrary.c

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/***************************************************************************
2+
* _ _ ____ _
3+
* Project ___| | | | _ \| |
4+
* / __| | | | |_) | |
5+
* | (__| |_| | _ <| |___
6+
* \___|\___/|_| \_\_____|
7+
*
8+
* Copyright (C) 2016 - 2017, Steve Holme, <steve_holme@hotmail.com>.
9+
*
10+
* All rights reserved.
11+
*
12+
* Permission to use, copy, modify, and distribute this software for any
13+
* purpose with or without fee is hereby granted, provided that the above
14+
* copyright notice and this permission notice appear in all copies.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
19+
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21+
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
22+
* THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
*
24+
* Except as contained in this notice, the name of a copyright holder shall
25+
* not be used in advertising or otherwise to promote the sale, use or other
26+
* dealings in this Software without prior written authorization of the
27+
* copyright holder.
28+
*
29+
***************************************************************************/
30+
31+
#if defined(_WIN32)
32+
33+
#include <windows.h>
34+
#include <tchar.h>
35+
36+
37+
HMODULE _Expat_LoadLibrary(LPCTSTR filename);
38+
39+
40+
#if !defined(LOAD_WITH_ALTERED_SEARCH_PATH)
41+
#define LOAD_WITH_ALTERED_SEARCH_PATH 0x00000008
42+
#endif
43+
44+
#if !defined(LOAD_LIBRARY_SEARCH_SYSTEM32)
45+
#define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800
46+
#endif
47+
48+
/* We use our own typedef here since some headers might lack these */
49+
typedef HMODULE (APIENTRY *LOADLIBRARYEX_FN)(LPCTSTR, HANDLE, DWORD);
50+
51+
/* See function definitions in winbase.h */
52+
#ifdef UNICODE
53+
# ifdef _WIN32_WCE
54+
# define LOADLIBARYEX L"LoadLibraryExW"
55+
# else
56+
# define LOADLIBARYEX "LoadLibraryExW"
57+
# endif
58+
#else
59+
# define LOADLIBARYEX "LoadLibraryExA"
60+
#endif
61+
62+
63+
/*
64+
* _Expat_LoadLibrary()
65+
*
66+
* This is used to dynamically load DLLs using the most secure method available
67+
* for the version of Windows that we are running on.
68+
*
69+
* Parameters:
70+
*
71+
* filename [in] - The filename or full path of the DLL to load. If only the
72+
* filename is passed then the DLL will be loaded from the
73+
* Windows system directory.
74+
*
75+
* Returns the handle of the module on success; otherwise NULL.
76+
*/
77+
HMODULE _Expat_LoadLibrary(LPCTSTR filename)
78+
{
79+
HMODULE hModule = NULL;
80+
LOADLIBRARYEX_FN pLoadLibraryEx = NULL;
81+
82+
/* Get a handle to kernel32 so we can access it's functions at runtime */
83+
HMODULE hKernel32 = GetModuleHandle(TEXT("kernel32"));
84+
if(!hKernel32)
85+
return NULL;
86+
87+
/* Attempt to find LoadLibraryEx() which is only available on Windows 2000
88+
and above */
89+
pLoadLibraryEx = (LOADLIBRARYEX_FN) GetProcAddress(hKernel32, LOADLIBARYEX);
90+
91+
/* Detect if there's already a path in the filename and load the library if
92+
there is. Note: Both back slashes and forward slashes have been supported
93+
since the earlier days of DOS at an API level although they are not
94+
supported by command prompt */
95+
if(_tcspbrk(filename, TEXT("\\/"))) {
96+
/** !checksrc! disable BANNEDFUNC 1 **/
97+
hModule = pLoadLibraryEx ?
98+
pLoadLibraryEx(filename, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) :
99+
LoadLibrary(filename);
100+
}
101+
/* Detect if KB2533623 is installed, as LOAD_LIBARY_SEARCH_SYSTEM32 is only
102+
supported on Windows Vista, Windows Server 2008, Windows 7 and Windows
103+
Server 2008 R2 with this patch or natively on Windows 8 and above */
104+
else if(pLoadLibraryEx && GetProcAddress(hKernel32, "AddDllDirectory")) {
105+
/* Load the DLL from the Windows system directory */
106+
hModule = pLoadLibraryEx(filename, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
107+
}
108+
else {
109+
/* Attempt to get the Windows system path */
110+
UINT systemdirlen = GetSystemDirectory(NULL, 0);
111+
if(systemdirlen) {
112+
/* Allocate space for the full DLL path (Room for the null terminator
113+
is included in systemdirlen) */
114+
size_t filenamelen = _tcslen(filename);
115+
TCHAR *path = malloc(sizeof(TCHAR) * (systemdirlen + 1 + filenamelen));
116+
if(path && GetSystemDirectory(path, systemdirlen)) {
117+
/* Calculate the full DLL path */
118+
_tcscpy(path + _tcslen(path), TEXT("\\"));
119+
_tcscpy(path + _tcslen(path), filename);
120+
121+
/* Load the DLL from the Windows system directory */
122+
/** !checksrc! disable BANNEDFUNC 1 **/
123+
hModule = pLoadLibraryEx ?
124+
pLoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) :
125+
LoadLibrary(path);
126+
127+
}
128+
free(path);
129+
}
130+
}
131+
132+
return hModule;
133+
}
134+
135+
#else /* defined(_WIN32) */
136+
137+
/* ISO C requires a translation unit to contain at least one declaration
138+
[-Wempty-translation-unit] */
139+
typedef int _TRANSLATION_UNIT_LOAD_LIBRARY_C_NOT_EMTPY;
140+
141+
#endif /* defined(_WIN32) */

Modules/expat/siphash.h

Lines changed: 46 additions & 16 deletions

0 commit comments

Comments
 (0)