mirror of https://github.com/FreeRDP/FreeRDP
winpr: add checks for *alloc
Add missing checks if memory allocation was successful. Also adapt caller(s) when possible.
This commit is contained in:
parent
20e2774aa8
commit
850de59b55
|
@ -837,6 +837,11 @@ MPPC_CONTEXT* mppc_context_new(DWORD CompressionLevel, BOOL Compressor)
|
|||
}
|
||||
|
||||
mppc->bs = BitStream_New();
|
||||
if (!mppc->bs)
|
||||
{
|
||||
free(mppc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mppc_context_reset(mppc, FALSE);
|
||||
}
|
||||
|
|
|
@ -187,7 +187,11 @@ int nla_client_init(rdpNla* nla)
|
|||
return -1;
|
||||
}
|
||||
|
||||
sspi_SecBufferAlloc(&nla->PublicKey, tls->PublicKeyLength);
|
||||
if (!sspi_SecBufferAlloc(&nla->PublicKey, tls->PublicKeyLength))
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to allocate sspic secBuffer");
|
||||
return -1;
|
||||
}
|
||||
CopyMemory(nla->PublicKey.pvBuffer, tls->PublicKey, tls->PublicKeyLength);
|
||||
length = sizeof(TERMSRV_SPN_PREFIX) + strlen(settings->ServerHostname);
|
||||
|
||||
|
@ -445,7 +449,11 @@ int nla_server_init(rdpNla* nla)
|
|||
{
|
||||
rdpTls* tls = nla->transport->tls;
|
||||
|
||||
sspi_SecBufferAlloc(&nla->PublicKey, tls->PublicKeyLength);
|
||||
if (!sspi_SecBufferAlloc(&nla->PublicKey, tls->PublicKeyLength))
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to allocate SecBuffer for public key");
|
||||
return -1;
|
||||
}
|
||||
CopyMemory(nla->PublicKey.pvBuffer, tls->PublicKey, tls->PublicKeyLength);
|
||||
|
||||
if (nla->SspiModule)
|
||||
|
@ -723,9 +731,10 @@ SECURITY_STATUS nla_encrypt_public_key_echo(rdpNla* nla)
|
|||
int public_key_length;
|
||||
|
||||
public_key_length = nla->PublicKey.cbBuffer;
|
||||
if (!sspi_SecBufferAlloc(&nla->pubKeyAuth, nla->ContextSizes.cbMaxSignature + public_key_length))
|
||||
return SEC_E_INSUFFICIENT_MEMORY;
|
||||
Buffers[0].BufferType = SECBUFFER_TOKEN; /* Signature */
|
||||
Buffers[1].BufferType = SECBUFFER_DATA; /* TLS Public Key */
|
||||
sspi_SecBufferAlloc(&nla->pubKeyAuth, nla->ContextSizes.cbMaxSignature + public_key_length);
|
||||
Buffers[0].cbBuffer = nla->ContextSizes.cbMaxSignature;
|
||||
Buffers[0].pvBuffer = nla->pubKeyAuth.pvBuffer;
|
||||
Buffers[1].cbBuffer = public_key_length;
|
||||
|
@ -958,7 +967,8 @@ void nla_encode_ts_credentials(rdpNla* nla)
|
|||
}
|
||||
|
||||
length = ber_sizeof_sequence(nla_sizeof_ts_credentials(nla));
|
||||
sspi_SecBufferAlloc(&nla->tsCredentials, length);
|
||||
if (!sspi_SecBufferAlloc(&nla->tsCredentials, length))
|
||||
return;
|
||||
s = Stream_New((BYTE*) nla->tsCredentials.pvBuffer, length);
|
||||
nla_write_ts_credentials(nla, s);
|
||||
|
||||
|
@ -980,9 +990,10 @@ SECURITY_STATUS nla_encrypt_ts_credentials(rdpNla* nla)
|
|||
|
||||
nla_encode_ts_credentials(nla);
|
||||
|
||||
if (!sspi_SecBufferAlloc(&nla->authInfo, nla->ContextSizes.cbMaxSignature + nla->tsCredentials.cbBuffer))
|
||||
return SEC_E_INSUFFICIENT_MEMORY;
|
||||
Buffers[0].BufferType = SECBUFFER_TOKEN; /* Signature */
|
||||
Buffers[1].BufferType = SECBUFFER_DATA; /* TSCredentials */
|
||||
sspi_SecBufferAlloc(&nla->authInfo, nla->ContextSizes.cbMaxSignature + nla->tsCredentials.cbBuffer);
|
||||
Buffers[0].cbBuffer = nla->ContextSizes.cbMaxSignature;
|
||||
Buffers[0].pvBuffer = nla->authInfo.pvBuffer;
|
||||
ZeroMemory(Buffers[0].pvBuffer, Buffers[0].cbBuffer);
|
||||
|
@ -1165,7 +1176,11 @@ int nla_decode_ts_request(rdpNla* nla, wStream* s)
|
|||
return -1;
|
||||
}
|
||||
|
||||
sspi_SecBufferAlloc(&nla->negoToken, length);
|
||||
if (!sspi_SecBufferAlloc(&nla->negoToken, length))
|
||||
{
|
||||
Stream_Free(s, TRUE);
|
||||
return -1;
|
||||
}
|
||||
Stream_Read(s, nla->negoToken.pvBuffer, length);
|
||||
nla->negoToken.cbBuffer = length;
|
||||
}
|
||||
|
@ -1180,7 +1195,11 @@ int nla_decode_ts_request(rdpNla* nla, wStream* s)
|
|||
return -1;
|
||||
}
|
||||
|
||||
sspi_SecBufferAlloc(&nla->authInfo, length);
|
||||
if (!sspi_SecBufferAlloc(&nla->authInfo, length))
|
||||
{
|
||||
Stream_Free(s, TRUE);
|
||||
return -1;
|
||||
}
|
||||
Stream_Read(s, nla->authInfo.pvBuffer, length);
|
||||
nla->authInfo.cbBuffer = length;
|
||||
}
|
||||
|
@ -1195,7 +1214,11 @@ int nla_decode_ts_request(rdpNla* nla, wStream* s)
|
|||
return -1;
|
||||
}
|
||||
|
||||
sspi_SecBufferAlloc(&nla->pubKeyAuth, length);
|
||||
if (!sspi_SecBufferAlloc(&nla->pubKeyAuth, length))
|
||||
{
|
||||
Stream_Free(s, TRUE);
|
||||
return -1;
|
||||
}
|
||||
Stream_Read(s, nla->pubKeyAuth.pvBuffer, length);
|
||||
nla->pubKeyAuth.cbBuffer = length;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,11 @@ int wf_directsound_activate(RdpsndServerContext* context)
|
|||
LPDIRECTSOUNDCAPTUREBUFFER pDSCB;
|
||||
|
||||
wfi = wf_info_get_instance();
|
||||
if (!wfi)
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to wfi instance");
|
||||
return 1;
|
||||
}
|
||||
WLog_DBG(TAG, "RDPSND (direct sound) Activated");
|
||||
hr = DirectSoundCaptureCreate8(NULL, &cap, NULL);
|
||||
|
||||
|
@ -95,6 +100,11 @@ DWORD WINAPI wf_rdpsnd_directsound_thread(LPVOID lpParam)
|
|||
LONG lLockSize = 0;
|
||||
|
||||
wfi = wf_info_get_instance();
|
||||
if (!wfi)
|
||||
{
|
||||
WLog_ERR(TAG, "Failed get instance");
|
||||
return 1;
|
||||
}
|
||||
|
||||
context = (wfPeerContext*)lpParam;
|
||||
rate = 1000 / 24;
|
||||
|
|
|
@ -40,24 +40,24 @@ static int _IDcount = 0;
|
|||
int wf_info_lock(wfInfo* wfi)
|
||||
{
|
||||
DWORD dRes;
|
||||
|
||||
|
||||
dRes = WaitForSingleObject(wfi->mutex, INFINITE);
|
||||
|
||||
switch (dRes)
|
||||
{
|
||||
case WAIT_ABANDONED:
|
||||
case WAIT_OBJECT_0:
|
||||
return TRUE;
|
||||
break;
|
||||
|
||||
case WAIT_TIMEOUT:
|
||||
return FALSE;
|
||||
break;
|
||||
|
||||
case WAIT_FAILED:
|
||||
WLog_ERR(TAG, "wf_info_lock failed with 0x%08X", GetLastError());
|
||||
return -1;
|
||||
break;
|
||||
case WAIT_ABANDONED:
|
||||
case WAIT_OBJECT_0:
|
||||
return TRUE;
|
||||
break;
|
||||
|
||||
case WAIT_TIMEOUT:
|
||||
return FALSE;
|
||||
break;
|
||||
|
||||
case WAIT_FAILED:
|
||||
WLog_ERR(TAG, "wf_info_lock failed with 0x%08X", GetLastError());
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
@ -66,24 +66,24 @@ int wf_info_lock(wfInfo* wfi)
|
|||
int wf_info_try_lock(wfInfo* wfi, DWORD dwMilliseconds)
|
||||
{
|
||||
DWORD dRes;
|
||||
|
||||
|
||||
dRes = WaitForSingleObject(wfi->mutex, dwMilliseconds);
|
||||
|
||||
switch (dRes)
|
||||
{
|
||||
case WAIT_ABANDONED:
|
||||
case WAIT_OBJECT_0:
|
||||
return TRUE;
|
||||
break;
|
||||
|
||||
case WAIT_TIMEOUT:
|
||||
return FALSE;
|
||||
break;
|
||||
|
||||
case WAIT_FAILED:
|
||||
WLog_ERR(TAG, "wf_info_try_lock failed with 0x%08X", GetLastError());
|
||||
return -1;
|
||||
break;
|
||||
case WAIT_ABANDONED:
|
||||
case WAIT_OBJECT_0:
|
||||
return TRUE;
|
||||
break;
|
||||
|
||||
case WAIT_TIMEOUT:
|
||||
return FALSE;
|
||||
break;
|
||||
|
||||
case WAIT_FAILED:
|
||||
WLog_ERR(TAG, "wf_info_try_lock failed with 0x%08X", GetLastError());
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
@ -103,9 +103,8 @@ int wf_info_unlock(wfInfo* wfi)
|
|||
wfInfo* wf_info_init()
|
||||
{
|
||||
wfInfo* wfi;
|
||||
|
||||
wfi = (wfInfo*) malloc(sizeof(wfInfo));
|
||||
ZeroMemory(wfi, sizeof(wfInfo));
|
||||
|
||||
wfi = (wfInfo*) calloc(1, sizeof(wfInfo));
|
||||
|
||||
if (wfi != NULL)
|
||||
{
|
||||
|
@ -114,40 +113,61 @@ wfInfo* wf_info_init()
|
|||
DWORD dwType;
|
||||
DWORD dwSize;
|
||||
DWORD dwValue;
|
||||
|
||||
|
||||
wfi->mutex = CreateMutex(NULL, FALSE, NULL);
|
||||
|
||||
if (wfi->mutex == NULL)
|
||||
if (wfi->mutex == NULL)
|
||||
{
|
||||
WLog_ERR(TAG, "CreateMutex error: %d", GetLastError());
|
||||
free(wfi);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wfi->updateSemaphore = CreateSemaphore(NULL, 0, 32, NULL);
|
||||
|
||||
if (!wfi->updateSemaphore)
|
||||
{
|
||||
WLog_ERR(TAG, "CreateSemaphore error: %d", GetLastError());
|
||||
CloseHandle(wfi->mutex);
|
||||
free(wfi);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wfi->updateThread = CreateThread(NULL, 0, wf_update_thread, wfi, CREATE_SUSPENDED, NULL);
|
||||
|
||||
if (!wfi->updateThread)
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to create update thread");
|
||||
CloseHandle(wfi->mutex);
|
||||
CloseHandle(wfi->updateSemaphore);
|
||||
free(wfi);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wfi->peers = (freerdp_peer**) calloc(1, sizeof(freerdp_peer*) * WF_INFO_MAXPEERS);
|
||||
if (!wfi->peers)
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to allocate memory for peer");
|
||||
CloseHandle(wfi->mutex);
|
||||
CloseHandle(wfi->updateSemaphore);
|
||||
CloseHandle(wfi->updateThread);
|
||||
free(wfi);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wfi->peers = (freerdp_peer**) malloc(sizeof(freerdp_peer*) * WF_INFO_MAXPEERS);
|
||||
memset(wfi->peers, 0, sizeof(freerdp_peer*) * WF_INFO_MAXPEERS);
|
||||
|
||||
//Set FPS
|
||||
wfi->framesPerSecond = WF_INFO_DEFAULT_FPS;
|
||||
|
||||
|
||||
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
|
||||
if (status == ERROR_SUCCESS)
|
||||
{
|
||||
if (RegQueryValueEx(hKey, _T("FramesPerSecond"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
|
||||
wfi->framesPerSecond = dwValue;
|
||||
wfi->framesPerSecond = dwValue;
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
RegCloseKey(hKey);
|
||||
|
||||
//Set input toggle
|
||||
wfi->input_disabled = FALSE;
|
||||
|
||||
|
||||
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
|
||||
if (status == ERROR_SUCCESS)
|
||||
{
|
||||
|
@ -186,12 +206,12 @@ void wf_info_peer_register(wfInfo* wfi, wfPeerContext* context)
|
|||
|
||||
context->info = wfi;
|
||||
context->updateEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
|
||||
|
||||
//get the offset of the top left corner of selected screen
|
||||
EnumDisplayMonitors(NULL, NULL, wf_info_monEnumCB, 0);
|
||||
_IDcount = 0;
|
||||
|
||||
#ifdef WITH_DXGI_1_2
|
||||
#ifdef WITH_DXGI_1_2
|
||||
if (wfi->peerCount == 0)
|
||||
wf_dxgi_init(wfi);
|
||||
#else
|
||||
|
@ -203,7 +223,7 @@ void wf_info_peer_register(wfInfo* wfi, wfPeerContext* context)
|
|||
}
|
||||
#endif
|
||||
//look trhough the array of peers until an empty slot
|
||||
for(i=0; i<WF_INFO_MAXPEERS; ++i)
|
||||
for(i=0; i<WF_INFO_MAXPEERS; ++i)
|
||||
{
|
||||
//empty index will be our peer id
|
||||
if (wfi->peers[i] == NULL)
|
||||
|
@ -218,7 +238,7 @@ void wf_info_peer_register(wfInfo* wfi, wfPeerContext* context)
|
|||
wfi->peerCount++;
|
||||
WLog_INFO(TAG, "Registering Peer: id=%d #=%d", peerId, wfi->peerCount);
|
||||
wf_info_unlock(wfi);
|
||||
|
||||
|
||||
wfreerdp_server_peer_callback_event(peerId, WF_SRV_CALLBACK_EVENT_CONNECT);
|
||||
}
|
||||
}
|
||||
|
@ -228,7 +248,7 @@ void wf_info_peer_unregister(wfInfo* wfi, wfPeerContext* context)
|
|||
if (wf_info_lock(wfi) > 0)
|
||||
{
|
||||
int peerId;
|
||||
|
||||
|
||||
peerId = ((rdpContext*) context)->peer->pId;
|
||||
wfi->peers[peerId] = NULL;
|
||||
wfi->peerCount--;
|
||||
|
@ -241,15 +261,15 @@ void wf_info_peer_unregister(wfInfo* wfi, wfPeerContext* context)
|
|||
#endif
|
||||
|
||||
wf_info_unlock(wfi);
|
||||
|
||||
|
||||
wfreerdp_server_peer_callback_event(peerId, WF_SRV_CALLBACK_EVENT_DISCONNECT);
|
||||
}
|
||||
}
|
||||
|
||||
BOOL wf_info_have_updates(wfInfo* wfi)
|
||||
{
|
||||
#ifdef WITH_DXGI_1_2
|
||||
if(wfi->framesWaiting == 0)
|
||||
#ifdef WITH_DXGI_1_2
|
||||
if (wfi->framesWaiting == 0)
|
||||
return FALSE;
|
||||
#else
|
||||
if (wfi->nextUpdate == wfi->lastUpdate)
|
||||
|
@ -260,11 +280,11 @@ BOOL wf_info_have_updates(wfInfo* wfi)
|
|||
|
||||
void wf_info_update_changes(wfInfo* wfi)
|
||||
{
|
||||
#ifdef WITH_DXGI_1_2
|
||||
#ifdef WITH_DXGI_1_2
|
||||
wf_dxgi_nextFrame(wfi, wfi->framesPerSecond * 1000);
|
||||
#else
|
||||
GETCHANGESBUF* buf;
|
||||
|
||||
|
||||
buf = (GETCHANGESBUF*) wfi->changeBuffer;
|
||||
wfi->nextUpdate = buf->buffer->counter;
|
||||
#endif
|
||||
|
@ -272,12 +292,12 @@ void wf_info_update_changes(wfInfo* wfi)
|
|||
|
||||
void wf_info_find_invalid_region(wfInfo* wfi)
|
||||
{
|
||||
#ifdef WITH_DXGI_1_2
|
||||
#ifdef WITH_DXGI_1_2
|
||||
wf_dxgi_getInvalidRegion(&wfi->invalid);
|
||||
#else
|
||||
int i;
|
||||
GETCHANGESBUF* buf;
|
||||
|
||||
|
||||
buf = (GETCHANGESBUF*) wfi->changeBuffer;
|
||||
|
||||
for (i = wfi->lastUpdate; i != wfi->nextUpdate; i = (i + 1) % MAXCHANGES_BUF)
|
||||
|
@ -285,10 +305,10 @@ void wf_info_find_invalid_region(wfInfo* wfi)
|
|||
LPRECT lpR = &buf->buffer->pointrect[i].rect;
|
||||
|
||||
//need to make sure we only get updates from the selected screen
|
||||
if ( (lpR->left >= wfi->servscreen_xoffset) &&
|
||||
(lpR->right <= (wfi->servscreen_xoffset + wfi->servscreen_width) ) &&
|
||||
(lpR->top >= wfi->servscreen_yoffset) &&
|
||||
(lpR->bottom <= (wfi->servscreen_yoffset + wfi->servscreen_height) ) )
|
||||
if ( (lpR->left >= wfi->servscreen_xoffset) &&
|
||||
(lpR->right <= (wfi->servscreen_xoffset + wfi->servscreen_width) ) &&
|
||||
(lpR->top >= wfi->servscreen_yoffset) &&
|
||||
(lpR->bottom <= (wfi->servscreen_yoffset + wfi->servscreen_height) ) )
|
||||
{
|
||||
UnionRect(&wfi->invalid, &wfi->invalid, lpR);
|
||||
}
|
||||
|
@ -334,20 +354,20 @@ void wf_info_getScreenData(wfInfo* wfi, long* width, long* height, BYTE** pBits,
|
|||
{
|
||||
*width = (wfi->invalid.right - wfi->invalid.left);
|
||||
*height = (wfi->invalid.bottom - wfi->invalid.top);
|
||||
|
||||
#ifdef WITH_DXGI_1_2
|
||||
|
||||
#ifdef WITH_DXGI_1_2
|
||||
wf_dxgi_getPixelData(wfi, pBits, pitch, &wfi->invalid);
|
||||
#else
|
||||
{
|
||||
long offset;
|
||||
GETCHANGESBUF* changes;
|
||||
changes = (GETCHANGESBUF*) wfi->changeBuffer;
|
||||
|
||||
|
||||
*width += 1;
|
||||
*height += 1;
|
||||
|
||||
|
||||
offset = (4 * wfi->invalid.left) + (wfi->invalid.top * wfi->virtscreen_width * 4);
|
||||
*pBits = ((BYTE*) (changes->Userbuffer)) + offset;
|
||||
*pBits = ((BYTE*) (changes->Userbuffer)) + offset;
|
||||
*pitch = wfi->virtscreen_width * 4;
|
||||
}
|
||||
#endif
|
||||
|
@ -355,17 +375,19 @@ void wf_info_getScreenData(wfInfo* wfi, long* width, long* height, BYTE** pBits,
|
|||
|
||||
BOOL CALLBACK wf_info_monEnumCB(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
|
||||
{
|
||||
wfInfo * wfi;
|
||||
|
||||
wfi = wf_info_get_instance();
|
||||
wfInfo * wfi;
|
||||
|
||||
if(_IDcount == wfi->screenID)
|
||||
wfi = wf_info_get_instance();
|
||||
if (!wfi)
|
||||
return FALSE;
|
||||
|
||||
if (_IDcount == wfi->screenID)
|
||||
{
|
||||
wfi->servscreen_xoffset = lprcMonitor->left;
|
||||
wfi->servscreen_yoffset = lprcMonitor->top;
|
||||
}
|
||||
|
||||
_IDcount++;
|
||||
|
||||
_IDcount++;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -86,6 +86,8 @@ void wf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
|
|||
wfInfo * wfi;
|
||||
|
||||
wfi = wf_info_get_instance();
|
||||
if (!wfi)
|
||||
return;
|
||||
|
||||
//width and height of primary screen (even in multimon setups
|
||||
width = (float) GetSystemMetrics(SM_CXSCREEN);
|
||||
|
@ -151,6 +153,8 @@ void wf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT1
|
|||
wfInfo * wfi;
|
||||
|
||||
wfi = wf_info_get_instance();
|
||||
if (!wfi)
|
||||
return;
|
||||
//width and height of primary screen (even in multimon setups
|
||||
width = (float) GetSystemMetrics(SM_CXSCREEN);
|
||||
height = (float) GetSystemMetrics(SM_CYSCREEN);
|
||||
|
|
|
@ -75,6 +75,8 @@ void set_screen_id(int id)
|
|||
wfInfo* wfi;
|
||||
|
||||
wfi = wf_info_get_instance();
|
||||
if (!wfi)
|
||||
return;
|
||||
wfi->screenID = id;
|
||||
|
||||
return;
|
||||
|
@ -91,6 +93,12 @@ DWORD WINAPI wf_server_main_loop(LPVOID lpParam)
|
|||
wfInfo* wfi;
|
||||
|
||||
wfi = wf_info_get_instance();
|
||||
if (!wfi)
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to get instance");
|
||||
return -1;
|
||||
}
|
||||
|
||||
wfi->force_all_disconnect = FALSE;
|
||||
|
||||
ZeroMemory(rfds, sizeof(rfds));
|
||||
|
@ -162,6 +170,8 @@ BOOL wfreerdp_server_stop(wfServer* server)
|
|||
wfInfo* wfi;
|
||||
|
||||
wfi = wf_info_get_instance();
|
||||
if (!wfi)
|
||||
return FALSE;
|
||||
WLog_INFO(TAG, "Stopping server");
|
||||
wfi->force_all_disconnect = TRUE;
|
||||
server->instance->Close(server->instance);
|
||||
|
@ -222,6 +232,8 @@ FREERDP_API UINT32 wfreerdp_server_num_peers()
|
|||
wfInfo* wfi;
|
||||
|
||||
wfi = wf_info_get_instance();
|
||||
if (!wfi)
|
||||
return -1;
|
||||
return wfi->peerCount;
|
||||
}
|
||||
|
||||
|
@ -231,6 +243,8 @@ FREERDP_API UINT32 wfreerdp_server_get_peer_hostname(int pId, wchar_t * dstStr)
|
|||
freerdp_peer* peer;
|
||||
|
||||
wfi = wf_info_get_instance();
|
||||
if (!wfi)
|
||||
return 0;
|
||||
peer = wfi->peers[pId];
|
||||
|
||||
if (peer)
|
||||
|
@ -254,6 +268,8 @@ FREERDP_API BOOL wfreerdp_server_peer_is_local(int pId)
|
|||
freerdp_peer* peer;
|
||||
|
||||
wfi = wf_info_get_instance();
|
||||
if (!wfi)
|
||||
return FALSE;
|
||||
peer = wfi->peers[pId];
|
||||
|
||||
if (peer)
|
||||
|
@ -272,6 +288,8 @@ FREERDP_API BOOL wfreerdp_server_peer_is_connected(int pId)
|
|||
freerdp_peer* peer;
|
||||
|
||||
wfi = wf_info_get_instance();
|
||||
if (!wfi)
|
||||
return FALSE;
|
||||
peer = wfi->peers[pId];
|
||||
|
||||
|
||||
|
@ -291,6 +309,8 @@ FREERDP_API BOOL wfreerdp_server_peer_is_activated(int pId)
|
|||
freerdp_peer* peer;
|
||||
|
||||
wfi = wf_info_get_instance();
|
||||
if (!wfi)
|
||||
return FALSE;
|
||||
peer = wfi->peers[pId];
|
||||
|
||||
if (peer)
|
||||
|
@ -309,6 +329,8 @@ FREERDP_API BOOL wfreerdp_server_peer_is_authenticated(int pId)
|
|||
freerdp_peer* peer;
|
||||
|
||||
wfi = wf_info_get_instance();
|
||||
if (!wfi)
|
||||
return FALSE;
|
||||
peer = wfi->peers[pId];
|
||||
|
||||
if (peer)
|
||||
|
|
|
@ -50,6 +50,7 @@ extern "C" {
|
|||
WINPR_API WINPR_SAM_ENTRY* SamLookupUserA(WINPR_SAM* sam, LPSTR User, UINT32 UserLength, LPSTR Domain, UINT32 DomainLength);
|
||||
WINPR_API WINPR_SAM_ENTRY* SamLookupUserW(WINPR_SAM* sam, LPWSTR User, UINT32 UserLength, LPWSTR Domain, UINT32 DomainLength);
|
||||
|
||||
WINPR_API void SamResetEntry(WINPR_SAM_ENTRY* entry);
|
||||
WINPR_API void SamFreeEntry(WINPR_SAM* sam, WINPR_SAM_ENTRY* entry);
|
||||
|
||||
WINPR_API WINPR_SAM* SamOpen(BOOL read_only);
|
||||
|
|
|
@ -37,8 +37,7 @@ ASN1module_t ASN1_CreateModule(ASN1uint32_t nVersion, ASN1encodingrule_e eRule,
|
|||
if (!((apfnEncoder) && (apfnDecoder) && (apfnFreeMemory) && (acbStructSize)))
|
||||
return NULL;
|
||||
|
||||
module = (ASN1module_t) malloc(sizeof(struct tagASN1module_t));
|
||||
ZeroMemory(module, sizeof(struct tagASN1module_t));
|
||||
module = (ASN1module_t) calloc(1, sizeof(struct tagASN1module_t));
|
||||
|
||||
if (module)
|
||||
{
|
||||
|
|
|
@ -219,13 +219,17 @@ UINT32 ClipboardRegisterFormat(wClipboard* clipboard, const char* name)
|
|||
|
||||
if ((clipboard->numFormats + 1) >= clipboard->maxFormats)
|
||||
{
|
||||
clipboard->maxFormats *= 2;
|
||||
UINT32 numFormats = clipboard->maxFormats * 2;
|
||||
wClipboardFormat *tmpFormat;
|
||||
|
||||
clipboard->formats = (wClipboardFormat*) realloc(clipboard->formats,
|
||||
clipboard->maxFormats * sizeof(wClipboardFormat));
|
||||
tmpFormat = (wClipboardFormat*) realloc(clipboard->formats,
|
||||
numFormats * sizeof(wClipboardFormat));
|
||||
|
||||
if (!clipboard->formats)
|
||||
if (!tmpFormat)
|
||||
return 0;
|
||||
|
||||
clipboard->formats = tmpFormat;
|
||||
clipboard->maxFormats = numFormats;
|
||||
}
|
||||
|
||||
format = &(clipboard->formats[clipboard->numFormats]);
|
||||
|
@ -267,14 +271,18 @@ BOOL ClipboardRegisterSynthesizer(wClipboard* clipboard, UINT32 formatId,
|
|||
|
||||
if (!synthesizer)
|
||||
{
|
||||
index = format->numSynthesizers++;
|
||||
wClipboardSynthesizer *tmpSynthesizer;
|
||||
UINT32 numSynthesizers = format->numSynthesizers + 1;
|
||||
|
||||
format->synthesizers = (wClipboardSynthesizer*) realloc(format->synthesizers,
|
||||
format->numSynthesizers * sizeof(wClipboardSynthesizer));
|
||||
tmpSynthesizer = (wClipboardSynthesizer*) realloc(format->synthesizers,
|
||||
numSynthesizers * sizeof(wClipboardSynthesizer));
|
||||
|
||||
if (!format->synthesizers)
|
||||
if (!tmpSynthesizer)
|
||||
return FALSE;
|
||||
|
||||
format->synthesizers = tmpSynthesizer;
|
||||
format->numSynthesizers = numSynthesizers;
|
||||
index = numSynthesizers - 1;
|
||||
synthesizer = &(format->synthesizers[index]);
|
||||
}
|
||||
|
||||
|
|
|
@ -101,6 +101,8 @@ static void* clipboard_synthesize_cf_locale(wClipboard* clipboard, UINT32 format
|
|||
UINT32* pDstData = NULL;
|
||||
|
||||
pDstData = (UINT32*) malloc(sizeof(UINT32));
|
||||
if (!pDstData)
|
||||
return NULL;
|
||||
*pDstData = 0x0409; /* English - United States */
|
||||
|
||||
return (void*) pDstData;
|
||||
|
@ -354,10 +356,17 @@ static void* clipboard_synthesize_html_format(wClipboard* clipboard, UINT32 form
|
|||
if (!pSrcData)
|
||||
{
|
||||
pSrcData = (char*) calloc(1, SrcSize + 1);
|
||||
if (!pSrcData)
|
||||
return NULL;
|
||||
CopyMemory(pSrcData, data, SrcSize);
|
||||
}
|
||||
|
||||
pDstData = (char*) calloc(1, SrcSize + 200);
|
||||
if (!pDstData)
|
||||
{
|
||||
free(pSrcData);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy(pDstData,
|
||||
"Version:0.9\r\n"
|
||||
|
|
|
@ -92,23 +92,41 @@ static void _CommInit()
|
|||
assert(_CommDevices == NULL);
|
||||
assert(_CommHandleCreator == NULL);
|
||||
|
||||
_Log = WLog_Get("com.winpr.comm");
|
||||
|
||||
_CommDevices = (COMM_DEVICE**)calloc(COMM_DEVICE_MAX+1, sizeof(COMM_DEVICE*));
|
||||
InitializeCriticalSection(&_CommDevicesLock);
|
||||
if (!_CommDevices)
|
||||
return;
|
||||
|
||||
_CommHandleCreator = (HANDLE_CREATOR*)malloc(sizeof(HANDLE_CREATOR));
|
||||
if (_CommHandleCreator)
|
||||
if (!InitializeCriticalSectionEx(&_CommDevicesLock, 0, 0))
|
||||
{
|
||||
_CommHandleCreator->IsHandled = IsCommDevice;
|
||||
_CommHandleCreator->CreateFileA = CommCreateFileA;
|
||||
|
||||
RegisterHandleCreator(_CommHandleCreator);
|
||||
free(_CommDevices);
|
||||
_CommDevices = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
_CommHandleCreator = (HANDLE_CREATOR*)malloc(sizeof(HANDLE_CREATOR));
|
||||
if (!_CommHandleCreator)
|
||||
{
|
||||
DeleteCriticalSection(&_CommDevicesLock);
|
||||
free(_CommDevices);
|
||||
_CommDevices = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
_CommHandleCreator->IsHandled = IsCommDevice;
|
||||
_CommHandleCreator->CreateFileA = CommCreateFileA;
|
||||
|
||||
if (!RegisterHandleCreator(_CommHandleCreator))
|
||||
{
|
||||
DeleteCriticalSection(&_CommDevicesLock);
|
||||
free(_CommDevices);
|
||||
free(_CommHandleCreator);
|
||||
_CommDevices = NULL;
|
||||
_CommHandleCreator = NULL;
|
||||
return;
|
||||
}
|
||||
_Log = WLog_Get("com.winpr.comm");
|
||||
assert(_Log != NULL);
|
||||
assert(_CommDevices != NULL);
|
||||
assert(_CommHandleCreator != NULL);
|
||||
}
|
||||
|
||||
|
||||
|
@ -124,6 +142,12 @@ static BOOL CommInitialized()
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (_CommHandleCreator == NULL)
|
||||
{
|
||||
SetLastError(ERROR_DLL_INIT_FAILED);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,8 @@ static BOOL test_generic(HANDLE hComm)
|
|||
}
|
||||
|
||||
pDcb = (DCB*)calloc(1, sizeof(DCB) * 2);
|
||||
if (!pDcb)
|
||||
return FALSE;
|
||||
pDcb->DCBlength = sizeof(DCB) * 2;
|
||||
result = GetCommState(hComm, pDcb);
|
||||
result = result && (pDcb->DCBlength == sizeof(DCB) * 2);
|
||||
|
|
|
@ -139,6 +139,11 @@ int convert_utf8_to_utf16(BYTE* lpMultiByteStr, BYTE* expected_lpWideCharStr, in
|
|||
}
|
||||
|
||||
lpWideCharStr = (LPWSTR) malloc(cchWideChar * sizeof(WCHAR));
|
||||
if (!lpWideCharStr)
|
||||
{
|
||||
printf("MultiByteToWideChar: unable to allocate memory for test\n");
|
||||
return -1;
|
||||
}
|
||||
lpWideCharStr[cchWideChar - 1] = 0xFFFF; /* should be overwritten if null terminator is inserted properly */
|
||||
length = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR) lpMultiByteStr, cbMultiByte + 1, lpWideCharStr, cchWideChar);
|
||||
|
||||
|
@ -206,6 +211,11 @@ int convert_utf16_to_utf8(BYTE* lpWideCharStr, BYTE* expected_lpMultiByteStr, in
|
|||
}
|
||||
|
||||
lpMultiByteStr = (LPSTR) malloc(cbMultiByte);
|
||||
if (!lpMultiByteStr)
|
||||
{
|
||||
printf("WideCharToMultiByte: unable to allocate memory for test\n");
|
||||
return -1;
|
||||
}
|
||||
lpMultiByteStr[cbMultiByte - 1] = 0xFF; /* should be overwritten if null terminator is inserted properly */
|
||||
length = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR) lpWideCharStr, cchWideChar + 1, lpMultiByteStr, cbMultiByte, NULL, NULL);
|
||||
|
||||
|
|
|
@ -156,10 +156,15 @@ BOOL CryptProtectMemory(LPVOID pData, DWORD cbData, DWORD dwFlags)
|
|||
return FALSE;
|
||||
|
||||
if (!g_ProtectedMemoryBlocks)
|
||||
{
|
||||
g_ProtectedMemoryBlocks = ListDictionary_New(TRUE);
|
||||
if (!g_ProtectedMemoryBlocks)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
pMemBlock = (WINPR_PROTECTED_MEMORY_BLOCK*) malloc(sizeof(WINPR_PROTECTED_MEMORY_BLOCK));
|
||||
ZeroMemory(pMemBlock, sizeof(WINPR_PROTECTED_MEMORY_BLOCK));
|
||||
pMemBlock = (WINPR_PROTECTED_MEMORY_BLOCK*) calloc(1, sizeof(WINPR_PROTECTED_MEMORY_BLOCK));
|
||||
if (!pMemBlock)
|
||||
return FALSE;
|
||||
|
||||
pMemBlock->pData = pData;
|
||||
pMemBlock->cbData = cbData;
|
||||
|
@ -187,6 +192,11 @@ BOOL CryptProtectMemory(LPVOID pData, DWORD cbData, DWORD dwFlags)
|
|||
|
||||
cbOut = pMemBlock->cbData + AES_BLOCK_SIZE - 1;
|
||||
pCipherText = (BYTE*) malloc(cbOut);
|
||||
if (!pCipherText)
|
||||
{
|
||||
free(pMemBlock);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
EVP_EncryptInit_ex(&(pMemBlock->enc), NULL, NULL, NULL, NULL);
|
||||
EVP_EncryptUpdate(&(pMemBlock->enc), pCipherText, &cbOut, pMemBlock->pData, pMemBlock->cbData);
|
||||
|
@ -221,6 +231,8 @@ BOOL CryptUnprotectMemory(LPVOID pData, DWORD cbData, DWORD dwFlags)
|
|||
|
||||
cbOut = pMemBlock->cbData + AES_BLOCK_SIZE - 1;
|
||||
pPlainText = (BYTE*) malloc(cbOut);
|
||||
if (!pPlainText)
|
||||
return FALSE;
|
||||
|
||||
EVP_DecryptInit_ex(&(pMemBlock->dec), NULL, NULL, NULL, NULL);
|
||||
EVP_DecryptUpdate(&(pMemBlock->dec), pPlainText, &cbOut, pMemBlock->pData, pMemBlock->cbData);
|
||||
|
|
|
@ -46,6 +46,12 @@ int TestCryptoCertEnumCertificatesInStore(int argc, char* argv[])
|
|||
status = CertGetNameString(pCertContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, NULL, 0);
|
||||
|
||||
pszNameString = (LPTSTR) malloc(status * sizeof(TCHAR));
|
||||
if (!pszNameString)
|
||||
{
|
||||
printf("Unable to allocate memory\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
status = CertGetNameString(pCertContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, pszNameString, status);
|
||||
|
||||
_tprintf(_T("Certificate #%d: %s\n"), index++, pszNameString);
|
||||
|
|
|
@ -17,6 +17,11 @@ int TestCryptoProtectMemory(int argc, char* argv[])
|
|||
cbCipherText = cbPlainText + (CRYPTPROTECTMEMORY_BLOCK_SIZE - (cbPlainText % CRYPTPROTECTMEMORY_BLOCK_SIZE));
|
||||
printf("cbPlainText: %d cbCipherText: %d\n", cbPlainText, cbCipherText);
|
||||
pCipherText = (BYTE*) malloc(cbCipherText);
|
||||
if (!pCipherText)
|
||||
{
|
||||
printf("Unable to allocate memory\n");
|
||||
return -1;
|
||||
}
|
||||
CopyMemory(pCipherText, pPlainText, cbPlainText);
|
||||
ZeroMemory(&pCipherText[cbPlainText], (cbCipherText - cbPlainText));
|
||||
|
||||
|
|
|
@ -41,6 +41,12 @@ int TestDsMakeSpn(int argc, char* argv[])
|
|||
|
||||
/* SpnLength includes null terminator */
|
||||
Spn = (LPTSTR) malloc(SpnLength * sizeof(TCHAR));
|
||||
if (!Spn)
|
||||
{
|
||||
_tprintf(_T("DsMakeSpn: Unable to allocate memroy\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
status = DsMakeSpn(testServiceClass, testServiceName, NULL, 0, NULL, &SpnLength, Spn);
|
||||
|
||||
|
|
|
@ -20,6 +20,9 @@ int TestEnvironmentGetSetEB(int argc, char* argv[])
|
|||
|
||||
/* Get the variable itself */
|
||||
p = (LPSTR) malloc(length);
|
||||
if (!p)
|
||||
return -1;
|
||||
|
||||
length = GetEnvironmentVariableEBA(lpszEnvironmentBlock,"DISPLAY", p, length);
|
||||
|
||||
printf("GetEnvironmentVariableA(WINPR_TEST_VARIABLE) = %s\n" , p);
|
||||
|
@ -97,6 +100,9 @@ int TestEnvironmentGetSetEB(int argc, char* argv[])
|
|||
free(lpszEnvironmentBlockNew);
|
||||
|
||||
lpszEnvironmentBlockNew = (LPTCH) malloc(1024);
|
||||
if (!lpszEnvironmentBlockNew)
|
||||
return -1;
|
||||
|
||||
memcpy(lpszEnvironmentBlockNew,lpszEnvironmentBlock,56);
|
||||
|
||||
/* Set variable in empty environment block */
|
||||
|
|
|
@ -24,6 +24,9 @@ int TestEnvironmentSetEnvironmentVariable(int argc, char* argv[])
|
|||
}
|
||||
|
||||
lpBuffer = (LPSTR) malloc(nSize);
|
||||
if (!lpBuffer)
|
||||
return -1;
|
||||
|
||||
nSize = GetEnvironmentVariableA(TEST_NAME, lpBuffer, nSize);
|
||||
|
||||
if (nSize != strlen(TEST_VALUE))
|
||||
|
|
|
@ -78,6 +78,11 @@ int TestErrorSetLastError(int argc, char* argv[])
|
|||
}
|
||||
|
||||
pLoopCount = _aligned_malloc(sizeof(LONG), sizeof(LONG));
|
||||
if (!pLoopCount)
|
||||
{
|
||||
printf("Unable to allocate memory\n");
|
||||
return -1;
|
||||
}
|
||||
*pLoopCount = 0;
|
||||
|
||||
threads[0] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) test_error_thread, (void*) (size_t) 0, 0, NULL);
|
||||
|
|
|
@ -274,7 +274,7 @@ static void _HandleCreatorsInit()
|
|||
if (!_HandleCreators)
|
||||
return;
|
||||
|
||||
if(!InitializeCriticalSectionEx(&_HandleCreatorsLock, 0, 0))
|
||||
if (!InitializeCriticalSectionEx(&_HandleCreatorsLock, 0, 0))
|
||||
{
|
||||
free(_HandleCreators);
|
||||
_HandleCreators = NULL;
|
||||
|
@ -414,12 +414,17 @@ HANDLE CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
|
|||
free(name);
|
||||
pNamedPipe = (WINPR_NAMED_PIPE*) calloc(1, sizeof(WINPR_NAMED_PIPE));
|
||||
if (!pNamedPipe)
|
||||
{
|
||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
hNamedPipe = (HANDLE) pNamedPipe;
|
||||
WINPR_HANDLE_SET_TYPE(pNamedPipe, HANDLE_TYPE_NAMED_PIPE);
|
||||
pNamedPipe->name = _strdup(lpFileName);
|
||||
if (!pNamedPipe->name)
|
||||
{
|
||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
free(pNamedPipe);
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
@ -636,8 +641,12 @@ HANDLE FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData)
|
|||
struct stat fileStat;
|
||||
WIN32_FILE_SEARCH* pFileSearch;
|
||||
ZeroMemory(lpFindFileData, sizeof(WIN32_FIND_DATAA));
|
||||
pFileSearch = (WIN32_FILE_SEARCH*) malloc(sizeof(WIN32_FILE_SEARCH));
|
||||
ZeroMemory(pFileSearch, sizeof(WIN32_FILE_SEARCH));
|
||||
pFileSearch = (WIN32_FILE_SEARCH*) calloc(1, sizeof(WIN32_FILE_SEARCH));
|
||||
if (!pFileSearch)
|
||||
{
|
||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
/* Separate lpFileName into path and pattern components */
|
||||
p = strrchr(lpFileName, '/');
|
||||
|
||||
|
@ -647,10 +656,23 @@ HANDLE FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData)
|
|||
index = (p - lpFileName);
|
||||
length = (p - lpFileName);
|
||||
pFileSearch->lpPath = (LPSTR) malloc(length + 1);
|
||||
if (!pFileSearch->lpPath)
|
||||
{
|
||||
free(pFileSearch);
|
||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
CopyMemory(pFileSearch->lpPath, lpFileName, length);
|
||||
pFileSearch->lpPath[length] = '\0';
|
||||
length = strlen(lpFileName) - index;
|
||||
pFileSearch->lpPattern = (LPSTR) malloc(length + 1);
|
||||
if (!pFileSearch->lpPattern)
|
||||
{
|
||||
free(pFileSearch->lpPath);
|
||||
free(pFileSearch);
|
||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
CopyMemory(pFileSearch->lpPattern, &lpFileName[index + 1], length);
|
||||
pFileSearch->lpPattern[length] = '\0';
|
||||
|
||||
|
|
|
@ -22,6 +22,11 @@ int TestFileFindFirstFile(int argc, char* argv[])
|
|||
#ifdef UNICODE
|
||||
length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
|
||||
BasePath = (WCHAR*) malloc((length + 1) * sizeof(WCHAR));
|
||||
if (!BasePath)
|
||||
{
|
||||
_tprintf(_T("Unable to allocate memory\n"));
|
||||
return -1;
|
||||
}
|
||||
MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR));
|
||||
BasePath[length] = 0;
|
||||
#else
|
||||
|
|
|
@ -24,6 +24,11 @@ int TestFileFindNextFile(int argc, char* argv[])
|
|||
#ifdef UNICODE
|
||||
length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
|
||||
BasePath = (WCHAR*) malloc((length + 1) * sizeof(WCHAR));
|
||||
if (!BasePath)
|
||||
{
|
||||
_tprintf(_T("Unable to allocate memory"));
|
||||
return -1;
|
||||
}
|
||||
MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR));
|
||||
BasePath[length] = 0;
|
||||
#else
|
||||
|
|
|
@ -17,6 +17,11 @@ int TestInterlockedAccess(int argc, char* argv[])
|
|||
/* InterlockedIncrement */
|
||||
|
||||
Addend = _aligned_malloc(sizeof(LONG), sizeof(LONG));
|
||||
if (!Addend)
|
||||
{
|
||||
printf("Failed to allocate memory\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
*Addend = 0;
|
||||
|
||||
|
@ -44,6 +49,12 @@ int TestInterlockedAccess(int argc, char* argv[])
|
|||
|
||||
Target = _aligned_malloc(sizeof(LONG), sizeof(LONG));
|
||||
|
||||
if (!Target)
|
||||
{
|
||||
printf("Failed to allocate memory\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
*Target = 0xAA;
|
||||
|
||||
oldValue = InterlockedExchange(Target, 0xFF);
|
||||
|
@ -81,6 +92,11 @@ int TestInterlockedAccess(int argc, char* argv[])
|
|||
/* InterlockedCompareExchange (*Destination == Comparand) */
|
||||
|
||||
Destination = _aligned_malloc(sizeof(LONG), sizeof(LONG));
|
||||
if (!Destination)
|
||||
{
|
||||
printf("Failed to allocate memory\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
*Destination = 0xAABBCCDD;
|
||||
|
||||
|
@ -119,6 +135,11 @@ int TestInterlockedAccess(int argc, char* argv[])
|
|||
/* InterlockedCompareExchange64 (*Destination == Comparand) */
|
||||
|
||||
Destination64 = _aligned_malloc(sizeof(LONGLONG), sizeof(LONGLONG));
|
||||
if (!Destination64)
|
||||
{
|
||||
printf("Failed to allocate memory\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
*Destination64 = 0x66778899AABBCCDD;
|
||||
|
||||
|
|
|
@ -20,6 +20,11 @@ int TestLibraryFreeLibrary(int argc, char* argv[])
|
|||
#ifdef UNICODE
|
||||
length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
|
||||
BasePath = (WCHAR*) malloc((length + 1) * sizeof(WCHAR));
|
||||
if (!BasePath)
|
||||
{
|
||||
_tprintf(_T("Memory allocation falied\n"));
|
||||
return -1;
|
||||
}
|
||||
MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR));
|
||||
BasePath[length] = 0;
|
||||
#else
|
||||
|
|
|
@ -25,6 +25,11 @@ int TestLibraryGetProcAddress(int argc, char* argv[])
|
|||
#ifdef UNICODE
|
||||
length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
|
||||
BasePath = (WCHAR*) malloc((length + 1) * sizeof(WCHAR));
|
||||
if (!BasePath)
|
||||
{
|
||||
_tprintf(_T("Memory allocation falied\n"));
|
||||
return -1;
|
||||
}
|
||||
MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR));
|
||||
BasePath[length] = 0;
|
||||
#else
|
||||
|
|
|
@ -20,6 +20,11 @@ int TestLibraryLoadLibrary(int argc, char* argv[])
|
|||
#ifdef UNICODE
|
||||
length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
|
||||
BasePath = (WCHAR*) malloc((length + 1) * sizeof(WCHAR));
|
||||
if (!BasePath)
|
||||
{
|
||||
_tprintf(_T("Memory allocation falied\n"));
|
||||
return -1;
|
||||
}
|
||||
MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR));
|
||||
BasePath[length] = 0;
|
||||
#else
|
||||
|
|
|
@ -161,6 +161,8 @@ NTSTATUS _RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString,
|
|||
DestinationString->MaximumLength = SourceString->MaximumLength * 2;
|
||||
|
||||
DestinationString->Buffer = (PWSTR) malloc(DestinationString->MaximumLength);
|
||||
if (!DestinationString->Buffer)
|
||||
return STATUS_NO_MEMORY;
|
||||
|
||||
for (index = 0; index < SourceString->MaximumLength; index++)
|
||||
{
|
||||
|
@ -214,12 +216,9 @@ NTSTATUS _NtCreateFile(PHANDLE FileHandle, ACCESS_MASK DesiredAccess,
|
|||
{
|
||||
WINPR_FILE* pFileHandle;
|
||||
|
||||
pFileHandle = (WINPR_FILE*) malloc(sizeof(WINPR_FILE));
|
||||
|
||||
pFileHandle = (WINPR_FILE*) calloc(1, sizeof(WINPR_FILE));
|
||||
if (!pFileHandle)
|
||||
return 0;
|
||||
|
||||
ZeroMemory(pFileHandle, sizeof(WINPR_FILE));
|
||||
return STATUS_NO_MEMORY;
|
||||
|
||||
pFileHandle->DesiredAccess = DesiredAccess;
|
||||
pFileHandle->FileAttributes = FileAttributes;
|
||||
|
@ -248,12 +247,10 @@ NTSTATUS _NtOpenFile(PHANDLE FileHandle, ACCESS_MASK DesiredAccess,
|
|||
{
|
||||
WINPR_FILE* pFileHandle;
|
||||
|
||||
pFileHandle = (WINPR_FILE*) malloc(sizeof(WINPR_FILE));
|
||||
pFileHandle = (WINPR_FILE*) calloc(1, sizeof(WINPR_FILE));
|
||||
|
||||
if (!pFileHandle)
|
||||
return 0;
|
||||
|
||||
ZeroMemory(pFileHandle, sizeof(WINPR_FILE));
|
||||
return STATUS_NO_MEMORY;
|
||||
|
||||
pFileHandle->DesiredAccess = DesiredAccess;
|
||||
pFileHandle->ShareAccess = ShareAccess;
|
||||
|
|
|
@ -189,8 +189,15 @@ char* GetPath_XDG_CACHE_HOME()
|
|||
return path;
|
||||
|
||||
home = GetPath_HOME();
|
||||
if (!home)
|
||||
return NULL;
|
||||
|
||||
path = (char*) malloc(strlen(home) + strlen("/.cache") + 1);
|
||||
if (!path)
|
||||
{
|
||||
free(home);
|
||||
return NULL;
|
||||
}
|
||||
sprintf(path, "%s%s", home, "/.cache");
|
||||
|
||||
free(home);
|
||||
|
@ -302,6 +309,8 @@ char* GetEnvironmentPath(char* name)
|
|||
if (nSize)
|
||||
{
|
||||
env = (LPSTR) malloc(nSize);
|
||||
if (!env)
|
||||
return NULL;
|
||||
nSize = GetEnvironmentVariableA(name, env, nSize);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,15 +36,12 @@
|
|||
|
||||
#include "../handle/handle.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef HAVE_AIO_H
|
||||
#undef HAVE_AIO_H /* disable for now, incomplete */
|
||||
|
|
|
@ -45,6 +45,11 @@ static void* named_pipe_client_thread(void* arg)
|
|||
|
||||
lpReadBuffer = (BYTE*) malloc(PIPE_BUFFER_SIZE);
|
||||
lpWriteBuffer = (BYTE*) malloc(PIPE_BUFFER_SIZE);
|
||||
if (!lpReadBuffer || !lpWriteBuffer)
|
||||
{
|
||||
printf("Error allocating memory\n");
|
||||
return NULL;
|
||||
}
|
||||
ZeroMemory(&overlapped, sizeof(OVERLAPPED));
|
||||
hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
overlapped.hEvent = hEvent;
|
||||
|
@ -153,6 +158,11 @@ static void* named_pipe_server_thread(void* arg)
|
|||
|
||||
lpReadBuffer = (BYTE*) malloc(PIPE_BUFFER_SIZE);
|
||||
lpWriteBuffer = (BYTE*) malloc(PIPE_BUFFER_SIZE);
|
||||
if (!lpReadBuffer || !lpWriteBuffer)
|
||||
{
|
||||
printf("Error allocating memory\n");
|
||||
return NULL;
|
||||
}
|
||||
nNumberOfBytesToRead = PIPE_BUFFER_SIZE;
|
||||
ZeroMemory(lpReadBuffer, PIPE_BUFFER_SIZE);
|
||||
fSuccess = ReadFile(hNamedPipe, lpReadBuffer, nNumberOfBytesToRead, NULL, &overlapped);
|
||||
|
|
|
@ -138,10 +138,15 @@ static RegVal* reg_load_value(Reg* reg, RegKey* key)
|
|||
length = p[1] - p[0];
|
||||
name = (char*) malloc(length + 1);
|
||||
if (!name)
|
||||
return 0;
|
||||
return NULL;
|
||||
memcpy(name, p[0], length);
|
||||
name[length] = '\0';
|
||||
value = (RegVal*) malloc(sizeof(RegVal));
|
||||
if (!value)
|
||||
{
|
||||
free(name);
|
||||
return NULL;
|
||||
}
|
||||
value->name = name;
|
||||
value->type = REG_NONE;
|
||||
value->next = value->prev = NULL;
|
||||
|
@ -253,6 +258,11 @@ static RegKey* reg_load_key(Reg* reg, RegKey* key)
|
|||
subkey->prev = subkey->next = NULL;
|
||||
length = p[1] - p[0];
|
||||
subkey->name = (char*) malloc(length + 1);
|
||||
if (!subkey->name)
|
||||
{
|
||||
free(subkey);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(subkey->name, p[0], length);
|
||||
subkey->name[length] = '\0';
|
||||
|
||||
|
|
|
@ -2781,9 +2781,16 @@ unsigned int determineMacOSXVersion()
|
|||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_OSRELEASE;
|
||||
sysctl(mib, 2, NULL, &len, NULL, 0);
|
||||
if (sysctl(mib, 2, NULL, &len, NULL, 0) != 0)
|
||||
return 0;
|
||||
kernelVersion = calloc(len, sizeof(char));
|
||||
sysctl(mib, 2, kernelVersion, &len, NULL, 0);
|
||||
if (!kernelVersion)
|
||||
return 0;
|
||||
if (sysctl(mib, 2, kernelVersion, &len, NULL, 0) != 0)
|
||||
{
|
||||
free(kernelVersion);
|
||||
return 0;
|
||||
}
|
||||
|
||||
tok = strtok(kernelVersion,".");
|
||||
while (tok)
|
||||
|
@ -2955,6 +2962,10 @@ int PCSC_InitializeSCardApi(void)
|
|||
if (nSize)
|
||||
{
|
||||
env = (LPSTR) malloc(nSize);
|
||||
if (!env)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
nSize = GetEnvironmentVariableA("WINPR_WINSCARD_LOCK_TRANSACTIONS", env, nSize);
|
||||
|
||||
if (strcmp(env, "1") == 0)
|
||||
|
@ -2971,6 +2982,8 @@ int PCSC_InitializeSCardApi(void)
|
|||
#ifdef __MACOSX__
|
||||
g_PCSCModule = LoadLibraryA("/System/Library/Frameworks/PCSC.framework/PCSC");
|
||||
OSXVersion = determineMacOSXVersion();
|
||||
if (OSXVersion == 0)
|
||||
return -1;
|
||||
#else
|
||||
g_PCSCModule = LoadLibraryA("libpcsclite.so.1");
|
||||
|
||||
|
|
|
@ -736,19 +736,22 @@ SECURITY_STATUS SEC_ENTRY ntlm_SetContextAttributesW(PCtxtHandle phContext, ULON
|
|||
if (AuthNtlmMessage->type == 1)
|
||||
{
|
||||
sspi_SecBufferFree(&context->NegotiateMessage);
|
||||
sspi_SecBufferAlloc(&context->NegotiateMessage, AuthNtlmMessage->length);
|
||||
if (!sspi_SecBufferAlloc(&context->NegotiateMessage, AuthNtlmMessage->length))
|
||||
return SEC_E_INSUFFICIENT_MEMORY;
|
||||
CopyMemory(context->NegotiateMessage.pvBuffer, AuthNtlmMessage->buffer, AuthNtlmMessage->length);
|
||||
}
|
||||
else if (AuthNtlmMessage->type == 2)
|
||||
{
|
||||
sspi_SecBufferFree(&context->ChallengeMessage);
|
||||
sspi_SecBufferAlloc(&context->ChallengeMessage, AuthNtlmMessage->length);
|
||||
if (!sspi_SecBufferAlloc(&context->ChallengeMessage, AuthNtlmMessage->length))
|
||||
return SEC_E_INSUFFICIENT_MEMORY;
|
||||
CopyMemory(context->ChallengeMessage.pvBuffer, AuthNtlmMessage->buffer, AuthNtlmMessage->length);
|
||||
}
|
||||
else if (AuthNtlmMessage->type == 3)
|
||||
{
|
||||
sspi_SecBufferFree(&context->AuthenticateMessage);
|
||||
sspi_SecBufferAlloc(&context->AuthenticateMessage, AuthNtlmMessage->length);
|
||||
if (!sspi_SecBufferAlloc(&context->AuthenticateMessage, AuthNtlmMessage->length))
|
||||
return SEC_E_INSUFFICIENT_MEMORY;
|
||||
CopyMemory(context->AuthenticateMessage.pvBuffer, AuthNtlmMessage->buffer, AuthNtlmMessage->length);
|
||||
}
|
||||
|
||||
|
|
|
@ -437,7 +437,8 @@ int ntlm_construct_authenticate_target_info(NTLM_CONTEXT* context)
|
|||
if (context->NTLMv2)
|
||||
size += 8; /* unknown 8-byte padding */
|
||||
|
||||
sspi_SecBufferAlloc(&context->AuthenticateTargetInfo, size);
|
||||
if (!sspi_SecBufferAlloc(&context->AuthenticateTargetInfo, size))
|
||||
return -1;
|
||||
AuthenticateTargetInfo = (NTLM_AV_PAIR*) context->AuthenticateTargetInfo.pvBuffer;
|
||||
ntlm_av_pair_list_init(AuthenticateTargetInfo);
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ int schannel_openssl_client_init(SCHANNEL_OPENSSL* context)
|
|||
if (!context->ssl)
|
||||
{
|
||||
WLog_ERR(TAG, "SSL_new failed");
|
||||
return -1;
|
||||
goto out_ssl_new_failed;
|
||||
}
|
||||
|
||||
context->bioRead = BIO_new(BIO_s_mem());
|
||||
|
@ -106,24 +106,66 @@ int schannel_openssl_client_init(SCHANNEL_OPENSSL* context)
|
|||
if (!context->bioRead)
|
||||
{
|
||||
WLog_ERR(TAG, "BIO_new failed");
|
||||
goto out_bio_read_failed;
|
||||
return -1;
|
||||
}
|
||||
|
||||
status = BIO_set_write_buf_size(context->bioRead, SCHANNEL_CB_MAX_TOKEN);
|
||||
if (status != 1)
|
||||
{
|
||||
WLog_ERR(TAG, "BIO_set_write_buf_size on bioRead failed");
|
||||
goto out_set_write_buf_read;
|
||||
}
|
||||
|
||||
context->bioWrite = BIO_new(BIO_s_mem());
|
||||
|
||||
if (!context->bioWrite)
|
||||
{
|
||||
WLog_ERR(TAG, "BIO_new failed");
|
||||
return -1;
|
||||
goto out_bio_write_failed;
|
||||
}
|
||||
|
||||
status = BIO_set_write_buf_size(context->bioWrite, SCHANNEL_CB_MAX_TOKEN);
|
||||
if (status != 1)
|
||||
{
|
||||
WLog_ERR(TAG, "BIO_set_write_buf_size on bioWrite failed");
|
||||
goto out_set_write_buf_write;
|
||||
}
|
||||
status = BIO_make_bio_pair(context->bioRead, context->bioWrite);
|
||||
if (status != 1)
|
||||
{
|
||||
WLog_ERR(TAG, "BIO_make_bio_pair failed");
|
||||
goto out_bio_pair;
|
||||
}
|
||||
SSL_set_bio(context->ssl, context->bioRead, context->bioWrite);
|
||||
context->ReadBuffer = (BYTE*) malloc(SCHANNEL_CB_MAX_TOKEN);
|
||||
if (!context->ReadBuffer)
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to allocate ReadBuffer");
|
||||
goto out_read_alloc;
|
||||
}
|
||||
context->WriteBuffer = (BYTE*) malloc(SCHANNEL_CB_MAX_TOKEN);
|
||||
if (!context->WriteBuffer)
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to allocate ReadBuffer");
|
||||
goto out_write_alloc;
|
||||
}
|
||||
return 0;
|
||||
|
||||
out_write_alloc:
|
||||
free(context->ReadBuffer);
|
||||
out_read_alloc:
|
||||
out_bio_pair:
|
||||
out_set_write_buf_write:
|
||||
BIO_free(context->bioWrite);
|
||||
out_bio_write_failed:
|
||||
out_set_write_buf_read:
|
||||
BIO_free(context->bioRead);
|
||||
out_bio_read_failed:
|
||||
SSL_free(context->ssl);
|
||||
out_ssl_new_failed:
|
||||
SSL_CTX_free(context->ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int schannel_openssl_server_init(SCHANNEL_OPENSSL* context)
|
||||
|
@ -177,7 +219,7 @@ int schannel_openssl_server_init(SCHANNEL_OPENSSL* context)
|
|||
if (SSL_CTX_use_RSAPrivateKey_file(context->ctx, "/tmp/localhost.key", SSL_FILETYPE_PEM) <= 0)
|
||||
{
|
||||
WLog_ERR(TAG, "SSL_CTX_use_RSAPrivateKey_file failed");
|
||||
return -1;
|
||||
goto out_rsa_key;
|
||||
}
|
||||
|
||||
context->ssl = SSL_new(context->ctx);
|
||||
|
@ -185,13 +227,13 @@ int schannel_openssl_server_init(SCHANNEL_OPENSSL* context)
|
|||
if (!context->ssl)
|
||||
{
|
||||
WLog_ERR(TAG, "SSL_new failed");
|
||||
return -1;
|
||||
goto out_ssl_new;
|
||||
}
|
||||
|
||||
if (SSL_use_certificate_file(context->ssl, "/tmp/localhost.crt", SSL_FILETYPE_PEM) <= 0)
|
||||
{
|
||||
WLog_ERR(TAG, "SSL_use_certificate_file failed");
|
||||
return -1;
|
||||
goto out_use_certificate;
|
||||
}
|
||||
|
||||
context->bioRead = BIO_new(BIO_s_mem());
|
||||
|
@ -199,24 +241,66 @@ int schannel_openssl_server_init(SCHANNEL_OPENSSL* context)
|
|||
if (!context->bioRead)
|
||||
{
|
||||
WLog_ERR(TAG, "BIO_new failed");
|
||||
return -1;
|
||||
goto out_bio_read;
|
||||
}
|
||||
|
||||
status = BIO_set_write_buf_size(context->bioRead, SCHANNEL_CB_MAX_TOKEN);
|
||||
if (status != 1)
|
||||
{
|
||||
WLog_ERR(TAG, "BIO_set_write_buf_size failed for bioRead");
|
||||
goto out_set_write_buf_read;
|
||||
}
|
||||
context->bioWrite = BIO_new(BIO_s_mem());
|
||||
|
||||
if (!context->bioWrite)
|
||||
{
|
||||
WLog_ERR(TAG, "BIO_new failed");
|
||||
return -1;
|
||||
goto out_bio_write;
|
||||
}
|
||||
|
||||
status = BIO_set_write_buf_size(context->bioWrite, SCHANNEL_CB_MAX_TOKEN);
|
||||
if (status != 1)
|
||||
{
|
||||
WLog_ERR(TAG, "BIO_set_write_buf_size failed for bioWrite");
|
||||
goto out_set_write_buf_write;
|
||||
}
|
||||
status = BIO_make_bio_pair(context->bioRead, context->bioWrite);
|
||||
if (status != 1)
|
||||
{
|
||||
WLog_ERR(TAG, "BIO_make_bio_pair failed");
|
||||
goto out_bio_pair;
|
||||
}
|
||||
SSL_set_bio(context->ssl, context->bioRead, context->bioWrite);
|
||||
context->ReadBuffer = (BYTE*) malloc(SCHANNEL_CB_MAX_TOKEN);
|
||||
if (!context->ReadBuffer)
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to allocate memory for ReadBuffer");
|
||||
goto out_read_buffer;
|
||||
}
|
||||
context->WriteBuffer = (BYTE*) malloc(SCHANNEL_CB_MAX_TOKEN);
|
||||
if (!context->WriteBuffer)
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to allocate memory for WriteBuffer");
|
||||
goto out_write_buffer;
|
||||
}
|
||||
return 0;
|
||||
|
||||
out_write_buffer:
|
||||
free(context->ReadBuffer);
|
||||
out_read_buffer:
|
||||
out_bio_pair:
|
||||
out_set_write_buf_write:
|
||||
BIO_free(context->bioWrite);
|
||||
out_bio_write:
|
||||
out_set_write_buf_read:
|
||||
BIO_free(context->bioRead);
|
||||
out_bio_read:
|
||||
out_use_certificate:
|
||||
SSL_free(context->ssl);
|
||||
out_ssl_new:
|
||||
out_rsa_key:
|
||||
SSL_CTX_free(context->ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SECURITY_STATUS schannel_openssl_client_process_tokens(SCHANNEL_OPENSSL* context, PSecBufferDesc pInput, PSecBufferDesc pOutput)
|
||||
|
@ -420,11 +504,10 @@ SECURITY_STATUS schannel_openssl_decrypt_message(SCHANNEL_OPENSSL* context, PSec
|
|||
SCHANNEL_OPENSSL* schannel_openssl_new()
|
||||
{
|
||||
SCHANNEL_OPENSSL* context;
|
||||
context = (SCHANNEL_OPENSSL*) malloc(sizeof(SCHANNEL_OPENSSL));
|
||||
context = (SCHANNEL_OPENSSL*) calloc(1, sizeof(SCHANNEL_OPENSSL));
|
||||
|
||||
if (context != NULL)
|
||||
{
|
||||
ZeroMemory(context, sizeof(SCHANNEL_OPENSSL));
|
||||
winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT);
|
||||
context->connected = FALSE;
|
||||
}
|
||||
|
|
|
@ -56,6 +56,8 @@ BOOL ShouldUseNativeSspi()
|
|||
return TRUE;
|
||||
|
||||
env = (LPSTR) malloc(nSize);
|
||||
if (!env)
|
||||
return TRUE;
|
||||
nSize = GetEnvironmentVariableA("WINPR_NATIVE_SSPI", env, nSize);
|
||||
|
||||
if (strcmp(env, "0") == 0)
|
||||
|
|
|
@ -243,9 +243,11 @@ void* sspi_SecBufferAlloc(PSecBuffer SecBuffer, ULONG size)
|
|||
if (!SecBuffer)
|
||||
return NULL;
|
||||
|
||||
SecBuffer->cbBuffer = size;
|
||||
SecBuffer->pvBuffer = calloc(1, size);
|
||||
if (!SecBuffer->pvBuffer)
|
||||
return NULL;
|
||||
|
||||
SecBuffer->cbBuffer = size;
|
||||
return SecBuffer->pvBuffer;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ set(${MODULE_PREFIX}_TESTS
|
|||
TestInitializeSecurityContext.c
|
||||
TestAcquireCredentialsHandle.c
|
||||
TestCredSSP.c
|
||||
TestSchannel.c
|
||||
#TestSchannel.c
|
||||
TestNTLM.c)
|
||||
|
||||
create_test_sourcelist(${MODULE_PREFIX}_SRCS
|
||||
|
|
|
@ -60,6 +60,12 @@ int TestInitializeSecurityContext(int argc, char* argv[])
|
|||
fContextReq = ISC_REQ_REPLAY_DETECT | ISC_REQ_SEQUENCE_DETECT | ISC_REQ_CONFIDENTIALITY | ISC_REQ_DELEGATE;
|
||||
|
||||
output_buffer = malloc(cbMaxLen);
|
||||
if (!output_buffer)
|
||||
{
|
||||
printf("Memory allocation failed\n");
|
||||
sspi_GlobalFinish();
|
||||
return -1;
|
||||
}
|
||||
|
||||
output_SecBuffer_desc.ulVersion = 0;
|
||||
output_SecBuffer_desc.cBuffers = 1;
|
||||
|
|
|
@ -389,6 +389,9 @@ int test_ntlm_server_authenticate(TEST_NTLM_SERVER* ntlm)
|
|||
ntlm->outputBuffer[0].BufferType = SECBUFFER_TOKEN;
|
||||
ntlm->outputBuffer[0].cbBuffer = ntlm->cbMaxToken;
|
||||
ntlm->outputBuffer[0].pvBuffer = malloc(ntlm->outputBuffer[0].cbBuffer);
|
||||
if (!ntlm->outputBuffer[0].pvBuffer)
|
||||
return -1;
|
||||
|
||||
status = ntlm->table->AcceptSecurityContext(&ntlm->credentials,
|
||||
ntlm->haveContext? &ntlm->context: NULL,
|
||||
&ntlm->inputBufferDesc, ntlm->fContextReq, SECURITY_NATIVE_DREP, &ntlm->context,
|
||||
|
@ -473,6 +476,11 @@ int TestNTLM(int argc, char* argv[])
|
|||
* Client Initialization
|
||||
*/
|
||||
client = test_ntlm_client_new();
|
||||
if (!client)
|
||||
{
|
||||
printf("Memory allocation failed");
|
||||
return -1;
|
||||
}
|
||||
status = test_ntlm_client_init(client, TEST_NTLM_USER, TEST_NTLM_DOMAIN, TEST_NTLM_PASSWORD);
|
||||
|
||||
if (status < 0)
|
||||
|
@ -485,6 +493,11 @@ int TestNTLM(int argc, char* argv[])
|
|||
* Server Initialization
|
||||
*/
|
||||
server = test_ntlm_server_new();
|
||||
if (!server)
|
||||
{
|
||||
printf("Memory allocation failed\n");
|
||||
return -1;
|
||||
}
|
||||
status = test_ntlm_server_init(server);
|
||||
|
||||
if (status < 0)
|
||||
|
@ -530,6 +543,12 @@ int TestNTLM(int argc, char* argv[])
|
|||
{
|
||||
pSecBuffer->cbBuffer = sizeof(TEST_NTLM_NEGOTIATE) -1;
|
||||
pSecBuffer->pvBuffer = (void*) malloc(pSecBuffer->cbBuffer);
|
||||
if (!pSecBuffer->pvBuffer)
|
||||
{
|
||||
printf("Memory allocation failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
CopyMemory(pSecBuffer->pvBuffer, TEST_NTLM_NEGOTIATE, pSecBuffer->cbBuffer);
|
||||
}
|
||||
|
||||
|
@ -578,6 +597,11 @@ int TestNTLM(int argc, char* argv[])
|
|||
SecPkgContext_AuthNtlmMessage AuthNtlmMessage;
|
||||
pSecBuffer->cbBuffer = sizeof(TEST_NTLM_CHALLENGE) -1;
|
||||
pSecBuffer->pvBuffer = (void*) malloc(pSecBuffer->cbBuffer);
|
||||
if (!pSecBuffer->pvBuffer)
|
||||
{
|
||||
printf("Memory allocation failed\n");
|
||||
return -1;
|
||||
}
|
||||
CopyMemory(pSecBuffer->pvBuffer, TEST_NTLM_CHALLENGE, pSecBuffer->cbBuffer);
|
||||
AuthNtlmMessage.type = 2;
|
||||
AuthNtlmMessage.length = pSecBuffer->cbBuffer;
|
||||
|
@ -610,6 +634,11 @@ int TestNTLM(int argc, char* argv[])
|
|||
{
|
||||
pSecBuffer->cbBuffer = sizeof(TEST_NTLM_AUTHENTICATE) -1;
|
||||
pSecBuffer->pvBuffer = (void*) malloc(pSecBuffer->cbBuffer);
|
||||
if (!pSecBuffer->pvBuffer)
|
||||
{
|
||||
printf("Memory allocation failed\n");
|
||||
return -1;
|
||||
}
|
||||
CopyMemory(pSecBuffer->pvBuffer, TEST_NTLM_AUTHENTICATE, pSecBuffer->cbBuffer);
|
||||
}
|
||||
|
||||
|
|
|
@ -241,6 +241,8 @@ int schannel_send(PSecurityFunctionTable table, HANDLE hPipe, PCtxtHandle phCont
|
|||
status = table->QueryContextAttributes(phContext, SECPKG_ATTR_STREAM_SIZES, &StreamSizes);
|
||||
ioBufferLength = StreamSizes.cbHeader + StreamSizes.cbMaximumMessage + StreamSizes.cbTrailer;
|
||||
ioBuffer = (BYTE*) malloc(ioBufferLength);
|
||||
if (!ioBuffer)
|
||||
return -1;
|
||||
ZeroMemory(ioBuffer, ioBufferLength);
|
||||
pMessageBuffer = ioBuffer + StreamSizes.cbHeader;
|
||||
CopyMemory(pMessageBuffer, buffer, length);
|
||||
|
@ -297,6 +299,8 @@ int schannel_recv(PSecurityFunctionTable table, HANDLE hPipe, PCtxtHandle phCont
|
|||
status = table->QueryContextAttributes(phContext, SECPKG_ATTR_STREAM_SIZES, &StreamSizes);
|
||||
ioBufferLength = StreamSizes.cbHeader + StreamSizes.cbMaximumMessage + StreamSizes.cbTrailer;
|
||||
ioBuffer = (BYTE*) malloc(ioBufferLength);
|
||||
if (!ioBuffer)
|
||||
return -1;
|
||||
ZeroMemory(ioBuffer, ioBufferLength);
|
||||
|
||||
if (!ReadFile(hPipe, ioBuffer, ioBufferLength, &NumberOfBytesRead, NULL))
|
||||
|
@ -401,6 +405,11 @@ static void* schannel_test_server_thread(void* arg)
|
|||
|
||||
cchNameString = CertGetNameString(pCertContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, NULL, 0);
|
||||
pszNameString = (LPTSTR) malloc(cchNameString * sizeof(TCHAR));
|
||||
if (!pszNameString)
|
||||
{
|
||||
printf("Memory allocation failed\n");
|
||||
return NULL;
|
||||
}
|
||||
cchNameString = CertGetNameString(pCertContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, pszNameString, cchNameString);
|
||||
_tprintf(_T("Certificate Name: %s\n"), pszNameString);
|
||||
ZeroMemory(&cred, sizeof(SCHANNEL_CRED));
|
||||
|
@ -422,8 +431,16 @@ static void* schannel_test_server_thread(void* arg)
|
|||
|
||||
extraData = FALSE;
|
||||
g_ServerWait = TRUE;
|
||||
lpTokenIn = (BYTE*) malloc(cbMaxToken);
|
||||
lpTokenOut = (BYTE*) malloc(cbMaxToken);
|
||||
if (!(lpTokenIn = (BYTE*) malloc(cbMaxToken)))
|
||||
{
|
||||
printf("Memory allocation failed\n");
|
||||
return NULL;
|
||||
}
|
||||
if (!(lpTokenOut = (BYTE*) malloc(cbMaxToken)))
|
||||
{
|
||||
printf("Memory allocation failed\n");
|
||||
return NULL;
|
||||
}
|
||||
fContextReq = ASC_REQ_STREAM |
|
||||
ASC_REQ_SEQUENCE_DETECT | ASC_REQ_REPLAY_DETECT |
|
||||
ASC_REQ_CONFIDENTIALITY | ASC_REQ_EXTENDED_ERROR;
|
||||
|
@ -691,8 +708,16 @@ int TestSchannel(int argc, char* argv[])
|
|||
ISC_REQ_SEQUENCE_DETECT | ISC_REQ_REPLAY_DETECT |
|
||||
ISC_REQ_CONFIDENTIALITY | ISC_RET_EXTENDED_ERROR |
|
||||
ISC_REQ_MANUAL_CRED_VALIDATION | ISC_REQ_INTEGRITY;
|
||||
lpTokenIn = (BYTE*) malloc(cbMaxToken);
|
||||
lpTokenOut = (BYTE*) malloc(cbMaxToken);
|
||||
if (!(lpTokenIn = (BYTE*) malloc(cbMaxToken)))
|
||||
{
|
||||
printf("Memory allocation failed\n");
|
||||
return -1;
|
||||
}
|
||||
if (!(lpTokenOut = (BYTE*) malloc(cbMaxToken)))
|
||||
{
|
||||
printf("Memory allocation failed\n");
|
||||
return -1;
|
||||
}
|
||||
ZeroMemory(&SecBuffer_in, sizeof(SecBuffer_in));
|
||||
ZeroMemory(&SecBuffer_out, sizeof(SecBuffer_out));
|
||||
ZeroMemory(&SecBufferDesc_in, sizeof(SecBufferDesc));
|
||||
|
|
|
@ -108,47 +108,51 @@ HANDLE CreateEventW(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset,
|
|||
WINPR_EVENT* event;
|
||||
|
||||
event = (WINPR_EVENT*) calloc(1, sizeof(WINPR_EVENT));
|
||||
if (event)
|
||||
if (!event)
|
||||
return NULL;
|
||||
event->bAttached = FALSE;
|
||||
event->bManualReset = bManualReset;
|
||||
event->ops = &ops;
|
||||
WINPR_HANDLE_SET_TYPE(event, HANDLE_TYPE_EVENT);
|
||||
|
||||
if (!event->bManualReset)
|
||||
{
|
||||
event->bAttached = FALSE;
|
||||
event->bManualReset = bManualReset;
|
||||
event->ops = &ops;
|
||||
|
||||
if (!event->bManualReset)
|
||||
{
|
||||
WLog_ERR(TAG, "auto-reset events not yet implemented");
|
||||
}
|
||||
|
||||
event->pipe_fd[0] = -1;
|
||||
event->pipe_fd[1] = -1;
|
||||
#ifdef HAVE_EVENTFD_H
|
||||
event->pipe_fd[0] = eventfd(0, EFD_NONBLOCK);
|
||||
|
||||
if (event->pipe_fd[0] < 0)
|
||||
{
|
||||
WLog_ERR(TAG, "failed to create event");
|
||||
free(event);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
if (pipe(event->pipe_fd) < 0)
|
||||
{
|
||||
WLog_ERR(TAG, "failed to create event");
|
||||
free(event);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
WINPR_HANDLE_SET_TYPE(event, HANDLE_TYPE_EVENT);
|
||||
|
||||
if (bInitialState)
|
||||
SetEvent(event);
|
||||
WLog_ERR(TAG, "auto-reset events not yet implemented");
|
||||
}
|
||||
|
||||
if (!cs.LockSemaphore)
|
||||
InitializeCriticalSection(&cs);
|
||||
event->pipe_fd[0] = -1;
|
||||
event->pipe_fd[1] = -1;
|
||||
#ifdef HAVE_EVENTFD_H
|
||||
event->pipe_fd[0] = eventfd(0, EFD_NONBLOCK);
|
||||
|
||||
if (event->pipe_fd[0] < 0)
|
||||
{
|
||||
WLog_ERR(TAG, "failed to create event");
|
||||
free(event);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
if (pipe(event->pipe_fd) < 0)
|
||||
{
|
||||
WLog_ERR(TAG, "failed to create event");
|
||||
free(event);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (bInitialState)
|
||||
SetEvent(event);
|
||||
|
||||
if (!cs.LockSemaphore && !InitializeCriticalSectionEx(&cs, 0, 0))
|
||||
{
|
||||
if (event->pipe_fd[0] != -1)
|
||||
close(event->pipe_fd[0]);
|
||||
if (event->pipe_fd[1] != -1)
|
||||
close(event->pipe_fd[1]);
|
||||
free(event);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (HANDLE)event;
|
||||
}
|
||||
|
|
|
@ -159,11 +159,23 @@ HANDLE CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lIniti
|
|||
|
||||
#else
|
||||
semaphore->sem = (winpr_sem_t*) malloc(sizeof(winpr_sem_t));
|
||||
if (!semaphore->sem)
|
||||
{
|
||||
WLog_ERR(TAG, "failed to allocate semaphore memory");
|
||||
free(semaphore);
|
||||
return NULL;
|
||||
}
|
||||
#if defined __APPLE__
|
||||
semaphore_create(mach_task_self(), semaphore->sem, SYNC_POLICY_FIFO, lMaximumCount);
|
||||
if (semaphore_create(mach_task_self(), semaphore->sem, SYNC_POLICY_FIFO, lMaximumCount) != KERN_SUCCESS)
|
||||
#else
|
||||
sem_init(semaphore->sem, 0, lMaximumCount);
|
||||
if (sem_init(semaphore->sem, 0, lMaximumCount) == -1)
|
||||
#endif
|
||||
{
|
||||
WLog_ERR(TAG, "failed to create semaphore");
|
||||
free(semaphore->sem);
|
||||
free(semaphore);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -201,6 +201,11 @@ static PVOID TestSynchCritical_Main(PVOID arg)
|
|||
dwThreadCount = sysinfo.dwNumberOfProcessors > 1 ? sysinfo.dwNumberOfProcessors : 2;
|
||||
|
||||
hThreads = (HANDLE*) calloc(dwThreadCount, sizeof(HANDLE));
|
||||
if (!hThreads)
|
||||
{
|
||||
printf("Problem allocating memory\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
for (j = 0; j < TEST_SYNC_CRITICAL_TEST1_RUNS; j++)
|
||||
{
|
||||
|
|
|
@ -41,6 +41,11 @@ int TestSynchWaitableTimerAPC(int argc, char* argv[])
|
|||
APC_DATA* apcData = NULL;
|
||||
|
||||
apcData = (APC_DATA*) malloc(sizeof(APC_DATA));
|
||||
if (!apcData)
|
||||
{
|
||||
printf("Memory allocation failed\n");
|
||||
return -1;
|
||||
}
|
||||
g_Event = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
hTimer = CreateWaitableTimer(NULL, FALSE, NULL);
|
||||
|
||||
|
|
|
@ -116,14 +116,20 @@ LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs)
|
|||
numArgs = 0;
|
||||
lpEscapedCmdLine = NULL;
|
||||
cmdLineLength = strlen(lpCmdLine);
|
||||
lpEscapedChars = (BOOL*) malloc((cmdLineLength + 1) * sizeof(BOOL));
|
||||
ZeroMemory(lpEscapedChars, (cmdLineLength + 1) * sizeof(BOOL));
|
||||
lpEscapedChars = (BOOL*) calloc(1, (cmdLineLength + 1) * sizeof(BOOL));
|
||||
if (!lpEscapedChars)
|
||||
return NULL;
|
||||
|
||||
if (strstr(lpCmdLine, "\\\""))
|
||||
{
|
||||
int i, n;
|
||||
char* pLastEnd = NULL;
|
||||
lpEscapedCmdLine = (char*) malloc((cmdLineLength + 1) * sizeof(char));
|
||||
if (!lpEscapedCmdLine)
|
||||
{
|
||||
free(lpEscapedChars);
|
||||
return NULL;
|
||||
}
|
||||
p = (char*) lpCmdLine;
|
||||
pLastEnd = (char*) lpCmdLine;
|
||||
pOutput = (char*) lpEscapedCmdLine;
|
||||
|
|
|
@ -89,6 +89,9 @@ char** EnvironmentBlockToEnvpA(LPCH lpszEnvironmentBlock)
|
|||
char** envp = NULL;
|
||||
|
||||
count = 0;
|
||||
if (!lpszEnvironmentBlock)
|
||||
return NULL;
|
||||
|
||||
p = (char*) lpszEnvironmentBlock;
|
||||
|
||||
while (p[0] && p[1])
|
||||
|
@ -102,12 +105,23 @@ char** EnvironmentBlockToEnvpA(LPCH lpszEnvironmentBlock)
|
|||
p = (char*) lpszEnvironmentBlock;
|
||||
|
||||
envp = (char**) calloc(count + 1, sizeof(char*));
|
||||
if (!envp)
|
||||
return NULL;
|
||||
envp[count] = NULL;
|
||||
|
||||
while (p[0] && p[1])
|
||||
{
|
||||
length = strlen(p);
|
||||
envp[index] = _strdup(p);
|
||||
if (!envp[index])
|
||||
{
|
||||
for (index -= 1; index >= 0; --index)
|
||||
{
|
||||
free(envp[index]);
|
||||
}
|
||||
free(envp);
|
||||
return NULL;
|
||||
}
|
||||
p += (length + 1);
|
||||
index++;
|
||||
}
|
||||
|
@ -149,6 +163,9 @@ char* FindApplicationPath(char* application)
|
|||
return application;
|
||||
|
||||
lpSystemPath = (LPSTR) malloc(nSize);
|
||||
if (!lpSystemPath)
|
||||
return NULL;
|
||||
|
||||
nSize = GetEnvironmentVariableA("PATH", lpSystemPath, nSize);
|
||||
|
||||
save = NULL;
|
||||
|
@ -199,6 +216,8 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||
lpszEnvironmentBlock = NULL;
|
||||
|
||||
pArgs = CommandLineToArgvA(lpCommandLine, &numArgs);
|
||||
if (!pArgs)
|
||||
return FALSE;
|
||||
|
||||
flags = 0;
|
||||
|
||||
|
@ -213,6 +232,8 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||
lpszEnvironmentBlock = GetEnvironmentStrings();
|
||||
envp = EnvironmentBlockToEnvpA(lpszEnvironmentBlock);
|
||||
}
|
||||
if (!envp)
|
||||
goto finish;
|
||||
|
||||
filename = FindApplicationPath(pArgs[0]);
|
||||
if (NULL == filename)
|
||||
|
|
|
@ -224,10 +224,16 @@ void* BufferPool_Take(wBufferPool* pool, int size)
|
|||
{
|
||||
if (!size)
|
||||
buffer = NULL;
|
||||
else if (pool->alignment)
|
||||
buffer = _aligned_malloc(size, pool->alignment);
|
||||
else
|
||||
buffer = malloc(size);
|
||||
{
|
||||
if (pool->alignment)
|
||||
buffer = _aligned_malloc(size, pool->alignment);
|
||||
else
|
||||
buffer = malloc(size);
|
||||
|
||||
if (!buffer)
|
||||
goto out_error;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -235,19 +241,16 @@ void* BufferPool_Take(wBufferPool* pool, int size)
|
|||
|
||||
if (maxSize < size)
|
||||
{
|
||||
void *newBuffer;
|
||||
if (pool->alignment)
|
||||
{
|
||||
_aligned_free(buffer);
|
||||
buffer = _aligned_malloc(size, pool->alignment);
|
||||
}
|
||||
newBuffer = _aligned_realloc(buffer, size, pool->alignment);
|
||||
else
|
||||
{
|
||||
void *newBuffer = realloc(buffer, size);
|
||||
if (!newBuffer)
|
||||
goto out_error;
|
||||
newBuffer = realloc(buffer, size);
|
||||
|
||||
buffer = newBuffer;
|
||||
}
|
||||
if (!newBuffer)
|
||||
goto out_error_no_free;
|
||||
|
||||
buffer = newBuffer;
|
||||
}
|
||||
|
||||
if (!BufferPool_ShiftAvailable(pool, foundIndex, -1))
|
||||
|
@ -279,9 +282,11 @@ void* BufferPool_Take(wBufferPool* pool, int size)
|
|||
return buffer;
|
||||
|
||||
out_error:
|
||||
if (buffer)
|
||||
if (pool->alignment)
|
||||
_aligned_free(buffer);
|
||||
else
|
||||
free(buffer);
|
||||
|
||||
out_error_no_free:
|
||||
if (pool->synchronized)
|
||||
LeaveCriticalSection(&pool->lock);
|
||||
return NULL;
|
||||
|
@ -448,6 +453,8 @@ wBufferPool* BufferPool_New(BOOL synchronized, int fixedSize, DWORD alignment)
|
|||
pool->size = 0;
|
||||
pool->capacity = 32;
|
||||
pool->array = (void**) malloc(sizeof(void*) * pool->capacity);
|
||||
if (!pool->array)
|
||||
goto out_error;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -456,14 +463,27 @@ wBufferPool* BufferPool_New(BOOL synchronized, int fixedSize, DWORD alignment)
|
|||
pool->aSize = 0;
|
||||
pool->aCapacity = 32;
|
||||
pool->aArray = (wBufferPoolItem*) malloc(sizeof(wBufferPoolItem) * pool->aCapacity);
|
||||
if (!pool->aArray)
|
||||
goto out_error;
|
||||
|
||||
pool->uSize = 0;
|
||||
pool->uCapacity = 32;
|
||||
pool->uArray = (wBufferPoolItem*) malloc(sizeof(wBufferPoolItem) * pool->uCapacity);
|
||||
if (!pool->uArray)
|
||||
{
|
||||
free(pool->aArray);
|
||||
goto out_error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pool;
|
||||
|
||||
out_error:
|
||||
if (pool->synchronized)
|
||||
DeleteCriticalSection(&pool->lock);
|
||||
free(pool);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void BufferPool_Free(wBufferPool* pool)
|
||||
|
|
|
@ -35,6 +35,8 @@ wKeyValuePair* KeyValuePair_New(void* key, void* value)
|
|||
wKeyValuePair* keyValuePair;
|
||||
|
||||
keyValuePair = (wKeyValuePair*) malloc(sizeof(wKeyValuePair));
|
||||
if (!keyValuePair)
|
||||
return NULL;
|
||||
|
||||
keyValuePair->key = key;
|
||||
keyValuePair->value = value;
|
||||
|
|
|
@ -125,7 +125,7 @@ int ListDictionary_GetKeys(wListDictionary* listDictionary, ULONG_PTR** ppKeys)
|
|||
ULONG_PTR* pKeys = NULL;
|
||||
wListDictionaryItem* item;
|
||||
|
||||
if (!ppKeys)
|
||||
if (!ppKeys || !listDictionary)
|
||||
return -1;
|
||||
|
||||
if (listDictionary->synchronized)
|
||||
|
@ -145,7 +145,16 @@ int ListDictionary_GetKeys(wListDictionary* listDictionary, ULONG_PTR** ppKeys)
|
|||
}
|
||||
|
||||
if (count)
|
||||
pKeys = (ULONG_PTR*) calloc(count, sizeof(ULONG_PTR));
|
||||
{
|
||||
pKeys = (ULONG_PTR *) calloc(count, sizeof(ULONG_PTR));
|
||||
if (!pKeys)
|
||||
{
|
||||
if (listDictionary->synchronized)
|
||||
LeaveCriticalSection(&listDictionary->lock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
index = 0;
|
||||
|
||||
|
@ -176,14 +185,14 @@ BOOL ListDictionary_Add(wListDictionary* listDictionary, void* key, void* value)
|
|||
{
|
||||
wListDictionaryItem* item;
|
||||
wListDictionaryItem* lastItem;
|
||||
BOOL ret = FALSE;
|
||||
|
||||
if (listDictionary->synchronized)
|
||||
EnterCriticalSection(&listDictionary->lock);
|
||||
|
||||
item = (wListDictionaryItem*) malloc(sizeof(wListDictionaryItem));
|
||||
|
||||
if (!item)
|
||||
return FALSE;
|
||||
goto out_error;
|
||||
|
||||
item->key = key;
|
||||
item->value = value;
|
||||
|
@ -204,10 +213,12 @@ BOOL ListDictionary_Add(wListDictionary* listDictionary, void* key, void* value)
|
|||
lastItem->next = item;
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
out_error:
|
||||
if (listDictionary->synchronized)
|
||||
LeaveCriticalSection(&listDictionary->lock);
|
||||
|
||||
return TRUE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -196,11 +196,21 @@ wMessageQueue* MessageQueue_New(const wObject *callback)
|
|||
queue->size = 0;
|
||||
|
||||
queue->capacity = 32;
|
||||
queue->array = (wMessage*) malloc(sizeof(wMessage) * queue->capacity);
|
||||
ZeroMemory(queue->array, sizeof(wMessage) * queue->capacity);
|
||||
queue->array = (wMessage*) calloc(1, sizeof(wMessage) * queue->capacity);
|
||||
if (!queue->array)
|
||||
{
|
||||
free(queue);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
InitializeCriticalSectionAndSpinCount(&queue->lock, 4000);
|
||||
queue->event = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
if (!queue->event)
|
||||
{
|
||||
free(queue->array);
|
||||
free(queue);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (callback)
|
||||
queue->object = *callback;
|
||||
|
|
|
@ -127,6 +127,12 @@ wObjectPool* ObjectPool_New(BOOL synchronized)
|
|||
|
||||
if (pool)
|
||||
{
|
||||
pool->array = (void**) malloc(sizeof(void*) * pool->capacity);
|
||||
if (!pool->array)
|
||||
{
|
||||
free(pool);
|
||||
return NULL;
|
||||
}
|
||||
pool->synchronized = synchronized;
|
||||
|
||||
if (pool->synchronized)
|
||||
|
@ -134,7 +140,6 @@ wObjectPool* ObjectPool_New(BOOL synchronized)
|
|||
|
||||
pool->size = 0;
|
||||
pool->capacity = 32;
|
||||
pool->array = (void**) malloc(sizeof(void*) * pool->capacity);
|
||||
}
|
||||
|
||||
return pool;
|
||||
|
|
|
@ -162,12 +162,16 @@ wReferenceTable* ReferenceTable_New(BOOL synchronized, void* context, REFERENCE_
|
|||
|
||||
if (referenceTable)
|
||||
{
|
||||
referenceTable->array = (wReference*) calloc(1, sizeof(wReference) * referenceTable->size);
|
||||
if (!referenceTable->array)
|
||||
{
|
||||
free(referenceTable);
|
||||
return NULL;
|
||||
}
|
||||
referenceTable->context = context;
|
||||
referenceTable->ReferenceFree = ReferenceFree;
|
||||
|
||||
referenceTable->size = 32;
|
||||
referenceTable->array = (wReference*) malloc(sizeof(wReference) * referenceTable->size);
|
||||
ZeroMemory(referenceTable->array, sizeof(wReference) * referenceTable->size);
|
||||
|
||||
referenceTable->synchronized = synchronized;
|
||||
InitializeCriticalSectionAndSpinCount(&referenceTable->lock, 4000);
|
||||
|
|
|
@ -209,7 +209,7 @@ void StreamPool_Return(wStreamPool* pool, wStream* s)
|
|||
new_cap = pool->aCapacity * 2;
|
||||
new_arr = (wStream**) realloc(pool->aArray, sizeof(wStream*) * new_cap);
|
||||
if (!new_arr)
|
||||
return;
|
||||
goto out_fail;
|
||||
pool->aCapacity = new_cap;
|
||||
pool->aArray = new_arr;
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ void StreamPool_Return(wStreamPool* pool, wStream* s)
|
|||
new_cap = pool->aCapacity / 2;
|
||||
new_arr = (wStream**) realloc(pool->aArray, sizeof(wStream*) * new_cap);
|
||||
if (!new_arr)
|
||||
return;
|
||||
goto out_fail;
|
||||
pool->aCapacity = new_cap;
|
||||
pool->aArray = new_arr;
|
||||
}
|
||||
|
@ -229,6 +229,7 @@ void StreamPool_Return(wStreamPool* pool, wStream* s)
|
|||
pool->aArray[(pool->aSize)++] = s;
|
||||
StreamPool_RemoveUsed(pool, s);
|
||||
|
||||
out_fail:
|
||||
if (pool->synchronized)
|
||||
LeaveCriticalSection(&pool->lock);
|
||||
}
|
||||
|
|
|
@ -170,11 +170,25 @@ wIniFileSection* IniFile_Section_New(const char* name)
|
|||
{
|
||||
wIniFileSection* section = malloc(sizeof(wIniFileSection));
|
||||
|
||||
if (!section)
|
||||
return NULL;
|
||||
|
||||
section->name = _strdup(name);
|
||||
if (!section->name)
|
||||
{
|
||||
free(section);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
section->nKeys = 0;
|
||||
section->cKeys = 64;
|
||||
section->keys = (wIniFileKey**) malloc(sizeof(wIniFileKey*) * section->cKeys);
|
||||
if (!section->keys)
|
||||
{
|
||||
free(section->name);
|
||||
free(section);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return section;
|
||||
}
|
||||
|
@ -426,6 +440,9 @@ char** IniFile_GetSectionNames(wIniFile* ini, int* count)
|
|||
}
|
||||
|
||||
sectionNames = (char**) malloc(length);
|
||||
if (!sectionNames)
|
||||
return NULL;
|
||||
|
||||
p = (char*) &((BYTE*) sectionNames)[sizeof(char*) * ini->nSections];
|
||||
|
||||
for (index = 0; index < ini->nSections; index++)
|
||||
|
@ -469,6 +486,9 @@ char** IniFile_GetSectionKeyNames(wIniFile* ini, const char* section, int* count
|
|||
}
|
||||
|
||||
keyNames = (char**) malloc(length);
|
||||
if (!keyNames)
|
||||
return NULL;
|
||||
|
||||
p = (char*) &((BYTE*) keyNames)[sizeof(char*) * pSection->nKeys];
|
||||
|
||||
for (index = 0; index < pSection->nKeys; index++)
|
||||
|
@ -672,6 +692,11 @@ wIniFile* IniFile_New()
|
|||
ini->nSections = 0;
|
||||
ini->cSections = 64;
|
||||
ini->sections = (wIniFileSection**) calloc(ini->cSections, sizeof(wIniFileSection*));
|
||||
if (!ini->sections)
|
||||
{
|
||||
free(ini);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return ini;
|
||||
|
|
|
@ -24,18 +24,9 @@
|
|||
#include <winpr/ntlm.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/windows.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/des.h>
|
||||
#include <openssl/md4.h>
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/rc4.h>
|
||||
#include <openssl/hmac.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/engine.h>
|
||||
|
||||
/**
|
||||
* Define NTOWFv1(Password, User, Domain) as
|
||||
|
@ -50,8 +41,8 @@ BYTE* NTOWFv1W(LPWSTR Password, UINT32 PasswordLength, BYTE* NtHash)
|
|||
if (!Password)
|
||||
return NULL;
|
||||
|
||||
if (!NtHash)
|
||||
NtHash = malloc(16);
|
||||
if (!NtHash && !(NtHash = malloc(16)))
|
||||
return NULL;
|
||||
|
||||
MD4_Init(&md4_ctx);
|
||||
MD4_Update(&md4_ctx, Password, PasswordLength);
|
||||
|
@ -64,7 +55,9 @@ BYTE* NTOWFv1A(LPSTR Password, UINT32 PasswordLength, BYTE* NtHash)
|
|||
{
|
||||
LPWSTR PasswordW = NULL;
|
||||
|
||||
PasswordW = (LPWSTR) malloc(PasswordLength * 2);
|
||||
if (!(PasswordW = (LPWSTR) malloc(PasswordLength * 2)))
|
||||
return NULL;
|
||||
|
||||
MultiByteToWideChar(CP_ACP, 0, Password, PasswordLength, PasswordW, PasswordLength);
|
||||
|
||||
NtHash = NTOWFv1W(PasswordW, PasswordLength * 2, NtHash);
|
||||
|
@ -90,12 +83,20 @@ BYTE* NTOWFv2W(LPWSTR Password, UINT32 PasswordLength, LPWSTR User,
|
|||
if ((!User) || (!Password))
|
||||
return NULL;
|
||||
|
||||
if (!NtHash)
|
||||
NtHash = (BYTE*) malloc(16);
|
||||
if (!NtHash && !(NtHash = (BYTE*) malloc(16)))
|
||||
return NULL;
|
||||
|
||||
NTOWFv1W(Password, PasswordLength, NtHashV1);
|
||||
if (!NTOWFv1W(Password, PasswordLength, NtHashV1))
|
||||
{
|
||||
free(NtHash);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buffer = (BYTE*) malloc(UserLength + DomainLength);
|
||||
if (!(buffer = (BYTE*) malloc(UserLength + DomainLength)))
|
||||
{
|
||||
free(NtHash);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Concatenate(UpperCase(User), Domain) */
|
||||
|
||||
|
@ -122,12 +123,16 @@ BYTE* NTOWFv2A(LPSTR Password, UINT32 PasswordLength, LPSTR User,
|
|||
DomainW = (LPWSTR) malloc(DomainLength * 2);
|
||||
PasswordW = (LPWSTR) malloc(PasswordLength * 2);
|
||||
|
||||
if (!UserW || !DomainW || !PasswordW)
|
||||
goto out_fail;
|
||||
|
||||
MultiByteToWideChar(CP_ACP, 0, User, UserLength, UserW, UserLength);
|
||||
MultiByteToWideChar(CP_ACP, 0, Domain, DomainLength, DomainW, DomainLength);
|
||||
MultiByteToWideChar(CP_ACP, 0, Password, PasswordLength, PasswordW, PasswordLength);
|
||||
|
||||
NtHash = NTOWFv2W(PasswordW, PasswordLength * 2, UserW, UserLength * 2, DomainW, DomainLength * 2, NtHash);
|
||||
|
||||
out_fail:
|
||||
free(UserW);
|
||||
free(DomainW);
|
||||
free(PasswordW);
|
||||
|
@ -142,10 +147,14 @@ BYTE* NTOWFv2FromHashW(BYTE* NtHashV1, LPWSTR User, UINT32 UserLength, LPWSTR Do
|
|||
if (!User)
|
||||
return NULL;
|
||||
|
||||
if (!NtHash)
|
||||
NtHash = (BYTE*) malloc(16);
|
||||
if (!NtHash && !(NtHash = (BYTE*) malloc(16)))
|
||||
return NULL;
|
||||
|
||||
buffer = (BYTE*) malloc(UserLength + DomainLength);
|
||||
if (!(buffer = (BYTE*) malloc(UserLength + DomainLength)))
|
||||
{
|
||||
free(NtHash);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Concatenate(UpperCase(User), Domain) */
|
||||
|
||||
|
@ -169,19 +178,21 @@ BYTE* NTOWFv2FromHashA(BYTE* NtHashV1, LPSTR User, UINT32 UserLength, LPSTR Doma
|
|||
{
|
||||
LPWSTR UserW = NULL;
|
||||
LPWSTR DomainW = NULL;
|
||||
LPWSTR PasswordW = NULL;
|
||||
|
||||
UserW = (LPWSTR) malloc(UserLength * 2);
|
||||
DomainW = (LPWSTR) malloc(DomainLength * 2);
|
||||
|
||||
if (!UserW || !DomainW)
|
||||
goto out_fail;
|
||||
|
||||
MultiByteToWideChar(CP_ACP, 0, User, UserLength, UserW, UserLength);
|
||||
MultiByteToWideChar(CP_ACP, 0, Domain, DomainLength, DomainW, DomainLength);
|
||||
|
||||
NtHash = NTOWFv2FromHashW(NtHashV1, UserW, UserLength * 2, DomainW, DomainLength * 2, NtHash);
|
||||
|
||||
out_fail:
|
||||
free(UserW);
|
||||
free(DomainW);
|
||||
free(PasswordW);
|
||||
|
||||
return NtHash;
|
||||
}
|
||||
|
|
|
@ -117,6 +117,8 @@ char* winpr_BinToHexString(const BYTE* data, int length, BOOL space)
|
|||
char bin2hex[] = "0123456789ABCDEF";
|
||||
n = space ? 3 : 2;
|
||||
p = (char*) malloc((length + 1) * n);
|
||||
if (p)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
|
|
|
@ -61,6 +61,11 @@ WINPR_SAM* SamOpen(BOOL read_only)
|
|||
if (fp)
|
||||
{
|
||||
sam = (WINPR_SAM*) malloc(sizeof(WINPR_SAM));
|
||||
if (!sam)
|
||||
{
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
sam->read_only = read_only;
|
||||
sam->fp = fp;
|
||||
}
|
||||
|
@ -82,6 +87,9 @@ static BOOL SamLookupStart(WINPR_SAM* sam)
|
|||
return FALSE;
|
||||
|
||||
sam->buffer = (char*) malloc(file_size + 2);
|
||||
if (!sam->buffer)
|
||||
return FALSE;
|
||||
|
||||
read_size = fread(sam->buffer, file_size, 1, sam->fp);
|
||||
|
||||
if (!read_size)
|
||||
|
@ -133,11 +141,12 @@ static void HexStrToBin(char* str, BYTE* bin, int length)
|
|||
}
|
||||
}
|
||||
|
||||
WINPR_SAM_ENTRY* SamReadEntry(WINPR_SAM* sam, WINPR_SAM_ENTRY* entry)
|
||||
BOOL SamReadEntry(WINPR_SAM *sam, WINPR_SAM_ENTRY *entry)
|
||||
{
|
||||
char* p[7];
|
||||
int LmHashLength;
|
||||
int NtHashLength;
|
||||
|
||||
p[0] = sam->line;
|
||||
p[1] = strchr(p[0], ':') + 1;
|
||||
p[2] = strchr(p[1], ':') + 1;
|
||||
|
@ -146,16 +155,24 @@ WINPR_SAM_ENTRY* SamReadEntry(WINPR_SAM* sam, WINPR_SAM_ENTRY* entry)
|
|||
p[5] = strchr(p[4], ':') + 1;
|
||||
p[6] = p[0] + strlen(p[0]);
|
||||
entry->UserLength = (UINT32)(p[1] - p[0] - 1);
|
||||
entry->User = (LPSTR) malloc(entry->UserLength + 1);
|
||||
if (!entry->User)
|
||||
return FALSE;
|
||||
entry->User[entry->UserLength] = '\0';
|
||||
entry->DomainLength = (UINT32)(p[2] - p[1] - 1);
|
||||
LmHashLength = (int)(p[3] - p[2] - 1);
|
||||
NtHashLength = (int)(p[4] - p[3] - 1);
|
||||
entry->User = (LPSTR) malloc(entry->UserLength + 1);
|
||||
memcpy(entry->User, p[0], entry->UserLength);
|
||||
entry->User[entry->UserLength] = '\0';
|
||||
|
||||
if (entry->DomainLength > 0)
|
||||
{
|
||||
entry->Domain = (LPSTR) malloc(entry->DomainLength + 1);
|
||||
if (!entry->Domain)
|
||||
{
|
||||
free(entry->User);
|
||||
entry->User = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
memcpy(entry->Domain, p[1], entry->DomainLength);
|
||||
entry->Domain[entry->DomainLength] = '\0';
|
||||
}
|
||||
|
@ -174,7 +191,7 @@ WINPR_SAM_ENTRY* SamReadEntry(WINPR_SAM* sam, WINPR_SAM_ENTRY* entry)
|
|||
HexStrToBin(p[3], (BYTE*) entry->NtHash, 16);
|
||||
}
|
||||
|
||||
return entry;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void SamFreeEntry(WINPR_SAM* sam, WINPR_SAM_ENTRY* entry)
|
||||
|
@ -191,13 +208,38 @@ void SamFreeEntry(WINPR_SAM* sam, WINPR_SAM_ENTRY* entry)
|
|||
}
|
||||
}
|
||||
|
||||
void SamResetEntry(WINPR_SAM_ENTRY* entry)
|
||||
{
|
||||
if (!entry)
|
||||
return;
|
||||
|
||||
if (entry->UserLength)
|
||||
{
|
||||
free(entry->User);
|
||||
entry->User = NULL;
|
||||
}
|
||||
|
||||
if (entry->DomainLength)
|
||||
{
|
||||
free(entry->Domain);
|
||||
entry->Domain = NULL;
|
||||
}
|
||||
ZeroMemory(entry->LmHash, sizeof(entry->LmHash));
|
||||
ZeroMemory(entry->NtHash, sizeof(entry->NtHash));
|
||||
}
|
||||
|
||||
|
||||
WINPR_SAM_ENTRY* SamLookupUserA(WINPR_SAM* sam, LPSTR User, UINT32 UserLength, LPSTR Domain, UINT32 DomainLength)
|
||||
{
|
||||
int length;
|
||||
BOOL found = 0;
|
||||
BOOL found = FALSE;
|
||||
WINPR_SAM_ENTRY* entry;
|
||||
entry = (WINPR_SAM_ENTRY*) malloc(sizeof(WINPR_SAM_ENTRY));
|
||||
SamLookupStart(sam);
|
||||
entry = (WINPR_SAM_ENTRY*) calloc(1, sizeof(WINPR_SAM_ENTRY));
|
||||
if (!entry)
|
||||
return NULL;
|
||||
|
||||
if (!SamLookupStart(sam))
|
||||
return NULL;
|
||||
|
||||
while (sam->line != NULL)
|
||||
{
|
||||
|
@ -207,7 +249,10 @@ WINPR_SAM_ENTRY* SamLookupUserA(WINPR_SAM* sam, LPSTR User, UINT32 UserLength, L
|
|||
{
|
||||
if (sam->line[0] != '#')
|
||||
{
|
||||
SamReadEntry(sam, entry);
|
||||
if (!SamReadEntry(sam, entry))
|
||||
{
|
||||
goto out_fail;
|
||||
}
|
||||
|
||||
if (strcmp(User, entry->User) == 0)
|
||||
{
|
||||
|
@ -216,10 +261,11 @@ WINPR_SAM_ENTRY* SamLookupUserA(WINPR_SAM* sam, LPSTR User, UINT32 UserLength, L
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
SamResetEntry(entry);
|
||||
sam->line = strtok(NULL, "\n");
|
||||
}
|
||||
|
||||
out_fail:
|
||||
SamLookupFinish(sam);
|
||||
|
||||
if (!found)
|
||||
|
@ -234,16 +280,20 @@ WINPR_SAM_ENTRY* SamLookupUserA(WINPR_SAM* sam, LPSTR User, UINT32 UserLength, L
|
|||
WINPR_SAM_ENTRY* SamLookupUserW(WINPR_SAM* sam, LPWSTR User, UINT32 UserLength, LPWSTR Domain, UINT32 DomainLength)
|
||||
{
|
||||
int length;
|
||||
BOOL Found = 0;
|
||||
BOOL Found = FALSE;
|
||||
BOOL UserMatch;
|
||||
BOOL DomainMatch;
|
||||
LPWSTR EntryUser;
|
||||
LPWSTR EntryUser = NULL;
|
||||
UINT32 EntryUserLength;
|
||||
LPWSTR EntryDomain;
|
||||
LPWSTR EntryDomain = NULL;
|
||||
UINT32 EntryDomainLength;
|
||||
WINPR_SAM_ENTRY* entry;
|
||||
entry = (WINPR_SAM_ENTRY*) malloc(sizeof(WINPR_SAM_ENTRY));
|
||||
SamLookupStart(sam);
|
||||
|
||||
if (!(entry = (WINPR_SAM_ENTRY*) calloc(1, sizeof(WINPR_SAM_ENTRY))))
|
||||
return NULL;
|
||||
|
||||
if (!SamLookupStart(sam))
|
||||
return NULL;
|
||||
|
||||
while (sam->line != NULL)
|
||||
{
|
||||
|
@ -255,7 +305,8 @@ WINPR_SAM_ENTRY* SamLookupUserW(WINPR_SAM* sam, LPWSTR User, UINT32 UserLength,
|
|||
{
|
||||
DomainMatch = 0;
|
||||
UserMatch = 0;
|
||||
entry = SamReadEntry(sam, entry);
|
||||
if (!SamReadEntry(sam, entry))
|
||||
goto out_fail;
|
||||
|
||||
if (DomainLength > 0)
|
||||
{
|
||||
|
@ -263,6 +314,8 @@ WINPR_SAM_ENTRY* SamLookupUserW(WINPR_SAM* sam, LPWSTR User, UINT32 UserLength,
|
|||
{
|
||||
EntryDomainLength = (UINT32) strlen(entry->Domain) * 2;
|
||||
EntryDomain = (LPWSTR) malloc(EntryDomainLength + 2);
|
||||
if (!EntryDomain)
|
||||
goto out_fail;
|
||||
MultiByteToWideChar(CP_ACP, 0, entry->Domain, EntryDomainLength / 2,
|
||||
(LPWSTR) EntryDomain, EntryDomainLength / 2);
|
||||
|
||||
|
@ -290,6 +343,8 @@ WINPR_SAM_ENTRY* SamLookupUserW(WINPR_SAM* sam, LPWSTR User, UINT32 UserLength,
|
|||
{
|
||||
EntryUserLength = (UINT32) strlen(entry->User) * 2;
|
||||
EntryUser = (LPWSTR) malloc(EntryUserLength + 2);
|
||||
if (!EntryUser)
|
||||
goto out_fail;
|
||||
MultiByteToWideChar(CP_ACP, 0, entry->User, EntryUserLength / 2,
|
||||
(LPWSTR) EntryUser, EntryUserLength / 2);
|
||||
|
||||
|
@ -305,16 +360,18 @@ WINPR_SAM_ENTRY* SamLookupUserW(WINPR_SAM* sam, LPWSTR User, UINT32 UserLength,
|
|||
|
||||
if (UserMatch && DomainMatch)
|
||||
{
|
||||
Found = 1;
|
||||
Found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SamResetEntry(entry);
|
||||
sam->line = strtok(NULL, "\n");
|
||||
}
|
||||
|
||||
out_fail:
|
||||
SamLookupFinish(sam);
|
||||
|
||||
if (!Found)
|
||||
|
|
|
@ -69,16 +69,29 @@ void WLog_BinaryAppender_SetOutputFilePath(wLog* log, wLogBinaryAppender* append
|
|||
|
||||
int WLog_BinaryAppender_Open(wLog* log, wLogBinaryAppender* appender)
|
||||
{
|
||||
DWORD ProcessId;
|
||||
|
||||
ProcessId = GetCurrentProcessId();
|
||||
|
||||
if (!log || !appender)
|
||||
return -1;
|
||||
|
||||
if (!appender->FileName)
|
||||
{
|
||||
appender->FileName = (char*) malloc(MAX_PATH);
|
||||
if (!appender->FileName)
|
||||
return -1;
|
||||
sprintf_s(appender->FileName, MAX_PATH, "%u.wlog", (unsigned int) GetCurrentProcessId());
|
||||
}
|
||||
|
||||
if (!appender->FilePath)
|
||||
{
|
||||
appender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog");
|
||||
if (!appender->FilePath)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!appender->FullFileName)
|
||||
{
|
||||
appender->FullFileName = GetCombinedPath(appender->FilePath, appender->FileName);
|
||||
if (!appender->FullFileName)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!PathFileExistsA(appender->FilePath))
|
||||
|
@ -87,17 +100,6 @@ int WLog_BinaryAppender_Open(wLog* log, wLogBinaryAppender* appender)
|
|||
UnixChangeFileMode(appender->FilePath, 0xFFFF);
|
||||
}
|
||||
|
||||
if (!appender->FileName)
|
||||
{
|
||||
appender->FileName = (char*) malloc(256);
|
||||
sprintf_s(appender->FileName, 256, "%u.wlog", (unsigned int) ProcessId);
|
||||
}
|
||||
|
||||
if (!appender->FullFileName)
|
||||
{
|
||||
appender->FullFileName = GetCombinedPath(appender->FilePath, appender->FileName);
|
||||
}
|
||||
|
||||
appender->FileDescriptor = fopen(appender->FullFileName, "a+");
|
||||
|
||||
if (!appender->FileDescriptor)
|
||||
|
|
|
@ -66,33 +66,37 @@ void WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender,
|
|||
|
||||
int WLog_FileAppender_Open(wLog* log, wLogFileAppender* appender)
|
||||
{
|
||||
DWORD ProcessId;
|
||||
|
||||
ProcessId = GetCurrentProcessId();
|
||||
|
||||
if (!log || !appender)
|
||||
return -1;
|
||||
|
||||
if (!appender->FilePath)
|
||||
{
|
||||
appender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog");
|
||||
}
|
||||
|
||||
if (!PathFileExistsA(appender->FilePath))
|
||||
{
|
||||
CreateDirectoryA(appender->FilePath, 0);
|
||||
UnixChangeFileMode(appender->FilePath, 0xFFFF);
|
||||
if (!appender->FilePath)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!appender->FileName)
|
||||
{
|
||||
appender->FileName = (char*) malloc(256);
|
||||
sprintf_s(appender->FileName, 256, "%u.log", (unsigned int) ProcessId);
|
||||
appender->FileName = (char*) malloc(MAX_PATH);
|
||||
if (!appender->FileName)
|
||||
return -1;
|
||||
|
||||
sprintf_s(appender->FileName, MAX_PATH, "%u.log", (unsigned int) GetCurrentProcessId());
|
||||
}
|
||||
|
||||
if (!appender->FullFileName)
|
||||
{
|
||||
appender->FullFileName = GetCombinedPath(appender->FilePath, appender->FileName);
|
||||
if (!appender->FullFileName)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!PathFileExistsA(appender->FilePath))
|
||||
{
|
||||
if (!CreateDirectoryA(appender->FilePath, 0))
|
||||
return -1;
|
||||
UnixChangeFileMode(appender->FilePath, 0xFFFF);
|
||||
}
|
||||
|
||||
appender->FileDescriptor = fopen(appender->FullFileName, "a+");
|
||||
|
|
|
@ -365,6 +365,11 @@ wLogLayout* WLog_Layout_New(wLog* log)
|
|||
if (nSize)
|
||||
{
|
||||
env = (LPSTR) malloc(nSize);
|
||||
if (!env)
|
||||
{
|
||||
free(layout);
|
||||
return NULL;
|
||||
}
|
||||
nSize = GetEnvironmentVariableA("WLOG_PREFIX", env, nSize);
|
||||
}
|
||||
|
||||
|
@ -377,6 +382,11 @@ wLogLayout* WLog_Layout_New(wLog* log)
|
|||
#else
|
||||
layout->FormatString = _strdup("[%hr:%mi:%se:%ml] [%pid:%tid] [%lv][%mn] - ");
|
||||
#endif
|
||||
if (!layout->FormatString)
|
||||
{
|
||||
free(layout);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,15 +36,23 @@ char* WLog_Message_GetOutputFileName(int id, const char* ext)
|
|||
char* FileName;
|
||||
char* FullFileName;
|
||||
|
||||
ProcessId = GetCurrentProcessId();
|
||||
|
||||
if (!(FileName = (char*) malloc(256)))
|
||||
return NULL;
|
||||
|
||||
FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog");
|
||||
|
||||
if (!PathFileExistsA(FilePath))
|
||||
CreateDirectoryA(FilePath, NULL);
|
||||
|
||||
FileName = (char*) malloc(256);
|
||||
{
|
||||
if (!CreateDirectoryA(FilePath, NULL))
|
||||
{
|
||||
free(FileName);
|
||||
free(FilePath);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
ProcessId = GetCurrentProcessId();
|
||||
if (id >= 0)
|
||||
sprintf_s(FileName, 256, "%u-%d.%s", (unsigned int) ProcessId, id, ext);
|
||||
else
|
||||
|
|
|
@ -85,6 +85,8 @@ void Pcap_Read_Record(wPcap* pcap, wPcapRecord* record)
|
|||
Pcap_Read_RecordHeader(pcap, &record->header);
|
||||
record->length = record->header.incl_len;
|
||||
record->data = malloc(record->length);
|
||||
if (!record->data)
|
||||
return;
|
||||
fread(record->data, record->length, 1, pcap->fp);
|
||||
}
|
||||
}
|
||||
|
@ -102,16 +104,18 @@ void Pcap_Add_Record(wPcap* pcap, void* data, UINT32 length)
|
|||
|
||||
if (!pcap->tail)
|
||||
{
|
||||
pcap->tail = (wPcapRecord*) malloc(sizeof(wPcapRecord));
|
||||
ZeroMemory(pcap->tail, sizeof(wPcapRecord));
|
||||
pcap->tail = (wPcapRecord*) calloc(1, sizeof(wPcapRecord));
|
||||
if (!pcap->tail)
|
||||
return;
|
||||
pcap->head = pcap->tail;
|
||||
pcap->record = pcap->head;
|
||||
record = pcap->tail;
|
||||
}
|
||||
else
|
||||
{
|
||||
record = (wPcapRecord*) malloc(sizeof(wPcapRecord));
|
||||
ZeroMemory(record, sizeof(wPcapRecord));
|
||||
record = (wPcapRecord*) calloc(1, sizeof(wPcapRecord));
|
||||
if (!record)
|
||||
return;
|
||||
pcap->tail->next = record;
|
||||
pcap->tail = record;
|
||||
}
|
||||
|
@ -168,7 +172,7 @@ BOOL Pcap_GetNext_Record(wPcap* pcap, wPcapRecord* record)
|
|||
|
||||
wPcap* Pcap_Open(char* name, BOOL write)
|
||||
{
|
||||
wPcap* pcap;
|
||||
wPcap* pcap = NULL;
|
||||
FILE* pcap_fp = fopen(name, write ? "w+b" : "rb");
|
||||
|
||||
if (!pcap_fp)
|
||||
|
@ -177,11 +181,10 @@ wPcap* Pcap_Open(char* name, BOOL write)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pcap = (wPcap*) malloc(sizeof(wPcap));
|
||||
pcap = (wPcap*) calloc(1, sizeof(wPcap));
|
||||
|
||||
if (pcap)
|
||||
{
|
||||
ZeroMemory(pcap, sizeof(wPcap));
|
||||
pcap->name = name;
|
||||
pcap->write = write;
|
||||
pcap->record_count = 0;
|
||||
|
@ -198,7 +201,7 @@ wPcap* Pcap_Open(char* name, BOOL write)
|
|||
pcap->header.network = 1; /* ethernet */
|
||||
Pcap_Write_Header(pcap, &pcap->header);
|
||||
}
|
||||
else if (pcap->fp)
|
||||
else
|
||||
{
|
||||
fseek(pcap->fp, 0, SEEK_END);
|
||||
pcap->file_size = (int) ftell(pcap->fp);
|
||||
|
@ -206,7 +209,6 @@ wPcap* Pcap_Open(char* name, BOOL write)
|
|||
Pcap_Read_Header(pcap, &pcap->header);
|
||||
}
|
||||
}
|
||||
|
||||
return pcap;
|
||||
}
|
||||
|
||||
|
|
|
@ -405,7 +405,9 @@ int WLog_ParseFilters()
|
|||
if (!env)
|
||||
return -1;
|
||||
|
||||
nSize = GetEnvironmentVariableA("WLOG_FILTER", env, nSize);
|
||||
if (!GetEnvironmentVariableA("WLOG_FILTER", env, nSize))
|
||||
return -1;
|
||||
|
||||
count = 1;
|
||||
p = env;
|
||||
|
||||
|
@ -587,12 +589,14 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger)
|
|||
env = (LPSTR) malloc(nSize);
|
||||
if (env)
|
||||
{
|
||||
nSize = GetEnvironmentVariableA("WLOG_LEVEL", env, nSize);
|
||||
iLevel = WLog_ParseLogLevel(env);
|
||||
if (GetEnvironmentVariableA("WLOG_LEVEL", env, nSize))
|
||||
{
|
||||
iLevel = WLog_ParseLogLevel(env);
|
||||
|
||||
if (iLevel >= 0)
|
||||
log->Level = (DWORD) iLevel;
|
||||
if (iLevel >= 0)
|
||||
log->Level = (DWORD) iLevel;
|
||||
|
||||
}
|
||||
free(env);
|
||||
}
|
||||
}
|
||||
|
@ -651,17 +655,17 @@ wLog* WLog_GetRoot()
|
|||
if (nSize)
|
||||
{
|
||||
env = (LPSTR) malloc(nSize);
|
||||
nSize = GetEnvironmentVariableA("WLOG_APPENDER", env, nSize);
|
||||
|
||||
if (env)
|
||||
{
|
||||
if (_stricmp(env, "CONSOLE") == 0)
|
||||
logAppenderType = WLOG_APPENDER_CONSOLE;
|
||||
else if (_stricmp(env, "FILE") == 0)
|
||||
logAppenderType = WLOG_APPENDER_FILE;
|
||||
else if (_stricmp(env, "BINARY") == 0)
|
||||
logAppenderType = WLOG_APPENDER_BINARY;
|
||||
|
||||
if (GetEnvironmentVariableA("WLOG_APPENDER", env, nSize))
|
||||
{
|
||||
if (_stricmp(env, "CONSOLE") == 0)
|
||||
logAppenderType = WLOG_APPENDER_CONSOLE;
|
||||
else if (_stricmp(env, "FILE") == 0)
|
||||
logAppenderType = WLOG_APPENDER_FILE;
|
||||
else if (_stricmp(env, "BINARY") == 0)
|
||||
logAppenderType = WLOG_APPENDER_BINARY;
|
||||
}
|
||||
free(env);
|
||||
}
|
||||
}
|
||||
|
@ -732,21 +736,15 @@ wLog* WLog_FindChild(LPCSTR name)
|
|||
wLog* WLog_Get(LPCSTR name)
|
||||
{
|
||||
wLog* log;
|
||||
wLog* root;
|
||||
if (!(root = WLog_GetRoot()))
|
||||
return NULL;
|
||||
|
||||
if (!(log = WLog_FindChild(name)))
|
||||
{
|
||||
wLog* root = WLog_GetRoot();
|
||||
if (!root)
|
||||
return NULL;
|
||||
if (!(log = WLog_New(name, root)))
|
||||
return NULL;
|
||||
if (WLog_AddChild(root, log))
|
||||
{
|
||||
WLog_Free(log);
|
||||
return NULL;
|
||||
}
|
||||
WLog_AddChild(root, log);
|
||||
}
|
||||
|
||||
return log;
|
||||
}
|
||||
|
||||
|
|
|
@ -678,7 +678,7 @@ static BOOL LoadAndInitialize(char* library)
|
|||
void InitializeWtsApiStubs_Env()
|
||||
{
|
||||
DWORD nSize;
|
||||
char* env = NULL;
|
||||
char *env = NULL;
|
||||
|
||||
if (g_WtsApi)
|
||||
return;
|
||||
|
@ -686,15 +686,15 @@ void InitializeWtsApiStubs_Env()
|
|||
nSize = GetEnvironmentVariableA("WTSAPI_LIBRARY", NULL, 0);
|
||||
|
||||
if (!nSize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
env = (LPSTR) malloc(nSize);
|
||||
nSize = GetEnvironmentVariableA("WTSAPI_LIBRARY", env, nSize);
|
||||
|
||||
if (env)
|
||||
LoadAndInitialize(env);
|
||||
{
|
||||
if (GetEnvironmentVariableA("WTSAPI_LIBRARY", env, nSize))
|
||||
LoadAndInitialize(env);
|
||||
free(env);
|
||||
}
|
||||
}
|
||||
|
||||
#define FREERDS_LIBRARY_NAME "libfreerds-fdsapi.so"
|
||||
|
|
|
@ -246,6 +246,8 @@ int makecert_print_command_line_help(int argc, char** argv)
|
|||
{
|
||||
length = strlen(arg->Name) + strlen(arg->Format) + 2;
|
||||
str = malloc(length + 1);
|
||||
if (!str)
|
||||
return -1;
|
||||
sprintf_s(str, length + 1, "%s %s", arg->Name, arg->Format);
|
||||
printf("%-20s", str);
|
||||
free(str);
|
||||
|
@ -311,6 +313,8 @@ char* x509_get_default_name()
|
|||
|
||||
GetComputerNameExA(ComputerNameNetBIOS, NULL, &nSize);
|
||||
ComputerName = (char*) malloc(nSize);
|
||||
if (!ComputerName)
|
||||
return NULL;
|
||||
GetComputerNameExA(ComputerNameNetBIOS, ComputerName, &nSize);
|
||||
|
||||
return ComputerName;
|
||||
|
@ -461,7 +465,11 @@ int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* pa
|
|||
char* fullpath;
|
||||
|
||||
if (!context->output_file)
|
||||
{
|
||||
context->output_file = _strdup(context->default_name);
|
||||
if (!context->output_file)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Output Certificate File
|
||||
|
@ -469,6 +477,8 @@ int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* pa
|
|||
|
||||
length = strlen(context->output_file);
|
||||
filename = malloc(length + 8);
|
||||
if (!filename)
|
||||
return -1;
|
||||
strcpy(filename, context->output_file);
|
||||
|
||||
if (context->crtFormat)
|
||||
|
@ -488,7 +498,7 @@ int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* pa
|
|||
if (fp)
|
||||
{
|
||||
BIO* bio;
|
||||
BYTE* x509_str;
|
||||
BYTE* x509_str = NULL;
|
||||
|
||||
if (context->pfxFormat)
|
||||
{
|
||||
|
@ -520,7 +530,6 @@ int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* pa
|
|||
offset = 0;
|
||||
length = 2048;
|
||||
x509_str = (BYTE*) malloc(length);
|
||||
|
||||
if (!x509_str)
|
||||
{
|
||||
free(filename);
|
||||
|
@ -598,11 +607,20 @@ int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* pa
|
|||
offset = 0;
|
||||
length = 2048;
|
||||
x509_str = (BYTE*) malloc(length);
|
||||
if (!x509_str)
|
||||
{
|
||||
BIO_free(bio);
|
||||
free(filename);
|
||||
free(fullpath);
|
||||
fclose (fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
status = BIO_read(bio, x509_str, length);
|
||||
|
||||
if (status < 0)
|
||||
{
|
||||
BIO_free(bio);
|
||||
free(filename);
|
||||
free(fullpath);
|
||||
fclose (fp);
|
||||
|
@ -637,8 +655,7 @@ int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* pa
|
|||
|
||||
if (status < 0)
|
||||
{
|
||||
if (x509_str)
|
||||
free (x509_str);
|
||||
free (x509_str);
|
||||
free(filename);
|
||||
free(fullpath);
|
||||
fclose (fp);
|
||||
|
@ -668,14 +685,21 @@ int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* pa
|
|||
|
||||
offset = 0;
|
||||
length = 2048;
|
||||
x509_str = (BYTE*) malloc(length);
|
||||
if (!(x509_str = (BYTE*) malloc(length)))
|
||||
{
|
||||
BIO_free(bio);
|
||||
free(filename);
|
||||
free(fullpath);
|
||||
fclose (fp);
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
status = BIO_read(bio, x509_str, length);
|
||||
|
||||
if (status < 0)
|
||||
{
|
||||
if (x509_str)
|
||||
free(x509_str);
|
||||
free(x509_str);
|
||||
free(filename);
|
||||
free(fullpath);
|
||||
fclose (fp);
|
||||
|
@ -757,6 +781,8 @@ int makecert_context_output_private_key_file(MAKECERT_CONTEXT* context, char* pa
|
|||
|
||||
length = strlen(context->output_file);
|
||||
filename = malloc(length + 8);
|
||||
if (!filename)
|
||||
return -1;
|
||||
strcpy(filename, context->output_file);
|
||||
strcpy(&filename[length], ".key");
|
||||
length = strlen(filename);
|
||||
|
@ -788,6 +814,13 @@ int makecert_context_output_private_key_file(MAKECERT_CONTEXT* context, char* pa
|
|||
offset = 0;
|
||||
length = 2048;
|
||||
x509_str = (BYTE*) malloc(length);
|
||||
if (!x509_str)
|
||||
{
|
||||
free (filename);
|
||||
free(fullpath);
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
status = BIO_read(bio, x509_str, length);
|
||||
|
||||
|
@ -1013,12 +1046,20 @@ int makecert_context_process(MAKECERT_CONTEXT* context, int argc, char** argv)
|
|||
|
||||
offset = 0;
|
||||
length = 2048;
|
||||
x509_str = (BYTE*) malloc(length + 1);
|
||||
if (!(x509_str = (BYTE*) malloc(length + 1)))
|
||||
{
|
||||
BIO_free(bio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
status = BIO_read(bio, x509_str, length);
|
||||
|
||||
if (status < 0)
|
||||
{
|
||||
BIO_free(bio);
|
||||
free(x509_str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
offset += status;
|
||||
|
||||
|
|
Loading…
Reference in New Issue