Skip to content

Commit

Permalink
Added extra malloc method to avoid early calls to the policy checks o…
Browse files Browse the repository at this point in the history
…n Windows.
  • Loading branch information
dlemstra committed Jun 24, 2022
1 parent 16f316e commit 57e7129
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
15 changes: 15 additions & 0 deletions MagickCore/nt-base-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "MagickCore/delegate.h"
#include "MagickCore/delegate-private.h"
#include "MagickCore/exception.h"
#include "MagickCore/memory_.h"
#include "MagickCore/splay-tree.h"

#if defined(__cplusplus) || defined(c_plusplus)
Expand Down Expand Up @@ -67,6 +68,20 @@ struct timezone

#endif

static inline void *NTAcquireQuantumMemory(const size_t count,
const size_t quantum)
{
size_t
size;

if (HeapOverflowSanityCheckGetSize(count,quantum,&size) != MagickFalse)
{
errno=ENOMEM;
return(NULL);
}
return(AcquireMagickMemory(size));
}

extern MagickPrivate char
*NTGetLastError(void);

Expand Down
13 changes: 7 additions & 6 deletions MagickCore/nt-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static inline char *create_utf8_string(const wchar_t *wideChar)
count=WideCharToMultiByte(CP_UTF8,0,wideChar,-1,NULL,0,NULL,NULL);
if (count < 0)
return((char *) NULL);
utf8=(char *) AcquireQuantumMemory(count+1,sizeof(*utf8));
utf8=(char *) NTAcquireQuantumMemory(count+1,sizeof(*utf8));
if (utf8 == (char *) NULL)
return((char *) NULL);
count=WideCharToMultiByte(CP_UTF8,0,wideChar,-1,utf8,count,NULL,NULL);
Expand Down Expand Up @@ -231,7 +231,7 @@ static unsigned char *NTGetRegistryValue(HKEY root,const char *key,DWORD flags,
LPBYTE
wide;

wide=(LPBYTE) AcquireQuantumMemory((const size_t) size,sizeof(*wide));
wide=(LPBYTE) NTAcquireQuantumMemory((const size_t) size,sizeof(*wide));
if (wide != (LPBYTE) NULL)
{
status=RegQueryValueExW(registry_key,wide_name,0,&type,wide,&size);
Expand Down Expand Up @@ -304,7 +304,7 @@ BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
*wide_path;

MagickCoreGenesis((const char *) NULL,MagickFalse);
wide_path=(wchar_t *) AcquireQuantumMemory(MagickPathExtent,
wide_path=(wchar_t *) NTAcquireQuantumMemory(MagickPathExtent,
sizeof(*wide_path));
if (wide_path == (wchar_t *) NULL)
return(FALSE);
Expand All @@ -321,7 +321,8 @@ BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
module_path[count+1]='\0';
break;
}
path=(char *) AcquireQuantumMemory(MagickPathExtent,16*sizeof(*path));
path=(char *) NTAcquireQuantumMemory(MagickPathExtent,
16*sizeof(*path));
if (path == (char *) NULL)
{
module_path=DestroyString(module_path);
Expand All @@ -337,7 +338,7 @@ BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
char
*variable;

variable=(char *) AcquireQuantumMemory(MagickPathExtent,
variable=(char *) NTAcquireQuantumMemory(MagickPathExtent,
16*sizeof(*variable));
if (variable == (char *) NULL)
{
Expand Down Expand Up @@ -470,7 +471,7 @@ MagickPrivate char **NTArgvToUTF8(const int argc,wchar_t **argv)
ssize_t
i;

utf8=(char **) AcquireQuantumMemory(argc,sizeof(*utf8));
utf8=(char **) NTAcquireQuantumMemory(argc,sizeof(*utf8));
if (utf8 == (char **) NULL)
ThrowFatalException(ResourceLimitFatalError,"UnableToConvertStringToARGV");
for (i=0; i < (ssize_t) argc; i++)
Expand Down
6 changes: 3 additions & 3 deletions MagickCore/utility-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static inline wchar_t *create_wchar_path(const char *utf8)

(void) FormatLocaleString(buffer,MagickPathExtent,"\\\\?\\%s",utf8);
count+=4;
longPath=(wchar_t *) AcquireQuantumMemory(count,sizeof(*longPath));
longPath=(wchar_t *) NTAcquireQuantumMemory(count,sizeof(*longPath));
if (longPath == (wchar_t *) NULL)
return((wchar_t *) NULL);
count=MultiByteToWideChar(CP_UTF8,0,buffer,-1,longPath,count);
Expand All @@ -88,12 +88,12 @@ static inline wchar_t *create_wchar_path(const char *utf8)
longPath=(wchar_t *) RelinquishMagickMemory(longPath);
if ((count < 5) || (count >= MAX_PATH))
return((wchar_t *) NULL);
wideChar=(wchar_t *) AcquireQuantumMemory((size_t) count-3,
wideChar=(wchar_t *) NTAcquireQuantumMemory((size_t) count-3,
sizeof(*wideChar));
wcscpy(wideChar,shortPath+4);
return(wideChar);
}
wideChar=(wchar_t *) AcquireQuantumMemory(count,sizeof(*wideChar));
wideChar=(wchar_t *) NTAcquireQuantumMemory(count,sizeof(*wideChar));
if (wideChar == (wchar_t *) NULL)
return((wchar_t *) NULL);
count=MultiByteToWideChar(CP_UTF8,0,utf8,-1,wideChar,count);
Expand Down

0 comments on commit 57e7129

Please sign in to comment.