Skip to content

Commit 19d3f22

Browse files
neerajsi-msftgitster
authored andcommitted
wrapper: make inclusion of Windows csprng header tightly scoped
Including NTSecAPI.h in git-compat-util.h causes build errors in any other file that includes winternl.h. NTSecAPI.h was included in order to get access to the RtlGenRandom cryptographically secure PRNG. This change scopes the inclusion of ntsecapi.h to wrapper.c, which is the only place that it's actually needed. The build breakage is due to the definition of UNICODE_STRING in NtSecApi.h: #ifndef _NTDEF_ typedef LSA_UNICODE_STRING UNICODE_STRING, *PUNICODE_STRING; typedef LSA_STRING STRING, *PSTRING ; #endif LsaLookup.h: typedef struct _LSA_UNICODE_STRING { USHORT Length; USHORT MaximumLength; #ifdef MIDL_PASS [size_is(MaximumLength/2), length_is(Length/2)] #endif // MIDL_PASS PWSTR Buffer; } LSA_UNICODE_STRING, *PLSA_UNICODE_STRING; winternl.h also defines UNICODE_STRING: typedef struct _UNICODE_STRING { USHORT Length; USHORT MaximumLength; PWSTR Buffer; } UNICODE_STRING; typedef UNICODE_STRING *PUNICODE_STRING; Both definitions have equivalent layouts. Apparently these internal Windows headers aren't designed to be included together. This is an oversight in the headers and does not represent an incompatibility between the APIs. Signed-off-by: Neeraj Singh <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c216290 commit 19d3f22

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

compat/winansi.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44

55
#undef NOGDI
66

7-
/*
8-
* Including the appropriate header file for RtlGenRandom causes MSVC to see a
9-
* redefinition of types in an incompatible way when including headers below.
10-
*/
11-
#undef HAVE_RTLGENRANDOM
127
#include "../git-compat-util.h"
138
#include <wingdi.h>
149
#include <winreg.h>

git-compat-util.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,6 @@
197197
#endif
198198
#include <windows.h>
199199
#define GIT_WINDOWS_NATIVE
200-
#ifdef HAVE_RTLGENRANDOM
201-
/* This is required to get access to RtlGenRandom. */
202-
#define SystemFunction036 NTAPI SystemFunction036
203-
#include <NTSecAPI.h>
204-
#undef SystemFunction036
205-
#endif
206200
#endif
207201

208202
#include <unistd.h>

wrapper.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
#include "cache.h"
55
#include "config.h"
66

7+
#ifdef HAVE_RTLGENRANDOM
8+
/* This is required to get access to RtlGenRandom. */
9+
#define SystemFunction036 NTAPI SystemFunction036
10+
#include <NTSecAPI.h>
11+
#undef SystemFunction036
12+
#endif
13+
714
static int memory_limit_check(size_t size, int gentle)
815
{
916
static size_t limit = 0;

0 commit comments

Comments
 (0)