Commit 5b22afd3 authored by Peter Urbanec's avatar Peter Urbanec Committed by Alexandre Julliard

wintab32: Avoid NULL pointer dereferences.

parent 2f7ec73a
...@@ -155,7 +155,8 @@ static void LoadTablet(void) ...@@ -155,7 +155,8 @@ static void LoadTablet(void)
{ {
TRACE("Initializing the tablet to hwnd %p\n",hwndDefault); TRACE("Initializing the tablet to hwnd %p\n",hwndDefault);
gLoaded= TRUE; gLoaded= TRUE;
pLoadTabletInfo(hwndDefault); if (pLoadTabletInfo)
pLoadTabletInfo(hwndDefault);
} }
int TABLET_PostTabletMessage(LPOPENCONTEXT newcontext, UINT msg, WPARAM wParam, int TABLET_PostTabletMessage(LPOPENCONTEXT newcontext, UINT msg, WPARAM wParam,
...@@ -558,6 +559,11 @@ int WINAPI WTPacketsGet(HCTX hCtx, int cMaxPkts, LPVOID lpPkts) ...@@ -558,6 +559,11 @@ int WINAPI WTPacketsGet(HCTX hCtx, int cMaxPkts, LPVOID lpPkts)
EnterCriticalSection(&csTablet); EnterCriticalSection(&csTablet);
context = TABLET_FindOpenContext(hCtx); context = TABLET_FindOpenContext(hCtx);
if (!context)
{
LeaveCriticalSection(&csTablet);
return 0;
}
if (lpPkts != NULL) if (lpPkts != NULL)
TABLET_BlankPacketData(context,lpPkts,cMaxPkts); TABLET_BlankPacketData(context,lpPkts,cMaxPkts);
...@@ -608,6 +614,11 @@ BOOL WINAPI WTPacket(HCTX hCtx, UINT wSerial, LPVOID lpPkt) ...@@ -608,6 +614,11 @@ BOOL WINAPI WTPacket(HCTX hCtx, UINT wSerial, LPVOID lpPkt)
EnterCriticalSection(&csTablet); EnterCriticalSection(&csTablet);
context = TABLET_FindOpenContext(hCtx); context = TABLET_FindOpenContext(hCtx);
if (!context)
{
LeaveCriticalSection(&csTablet);
return 0;
}
rc = TABLET_FindPacket(context ,wSerial, &wtp); rc = TABLET_FindPacket(context ,wSerial, &wtp);
...@@ -642,6 +653,12 @@ BOOL WINAPI WTEnable(HCTX hCtx, BOOL fEnable) ...@@ -642,6 +653,12 @@ BOOL WINAPI WTEnable(HCTX hCtx, BOOL fEnable)
EnterCriticalSection(&csTablet); EnterCriticalSection(&csTablet);
context = TABLET_FindOpenContext(hCtx); context = TABLET_FindOpenContext(hCtx);
if (!context)
{
LeaveCriticalSection(&csTablet);
return 0;
}
/* if we want to enable and it is not enabled then */ /* if we want to enable and it is not enabled then */
if(fEnable && !context->enabled) if(fEnable && !context->enabled)
{ {
...@@ -742,6 +759,12 @@ BOOL WINAPI WTGetA(HCTX hCtx, LPLOGCONTEXTA lpLogCtx) ...@@ -742,6 +759,12 @@ BOOL WINAPI WTGetA(HCTX hCtx, LPLOGCONTEXTA lpLogCtx)
EnterCriticalSection(&csTablet); EnterCriticalSection(&csTablet);
context = TABLET_FindOpenContext(hCtx); context = TABLET_FindOpenContext(hCtx);
if (!context)
{
LeaveCriticalSection(&csTablet);
return 0;
}
LOGCONTEXTWtoA(&context->context, lpLogCtx); LOGCONTEXTWtoA(&context->context, lpLogCtx);
LeaveCriticalSection(&csTablet); LeaveCriticalSection(&csTablet);
...@@ -761,6 +784,12 @@ BOOL WINAPI WTGetW(HCTX hCtx, LPLOGCONTEXTW lpLogCtx) ...@@ -761,6 +784,12 @@ BOOL WINAPI WTGetW(HCTX hCtx, LPLOGCONTEXTW lpLogCtx)
EnterCriticalSection(&csTablet); EnterCriticalSection(&csTablet);
context = TABLET_FindOpenContext(hCtx); context = TABLET_FindOpenContext(hCtx);
if (!context)
{
LeaveCriticalSection(&csTablet);
return 0;
}
memmove(lpLogCtx,&context->context,sizeof(LOGCONTEXTW)); memmove(lpLogCtx,&context->context,sizeof(LOGCONTEXTW));
LeaveCriticalSection(&csTablet); LeaveCriticalSection(&csTablet);
...@@ -888,7 +917,7 @@ int WINAPI WTPacketsPeek(HCTX hCtx, int cMaxPkts, LPVOID lpPkts) ...@@ -888,7 +917,7 @@ int WINAPI WTPacketsPeek(HCTX hCtx, int cMaxPkts, LPVOID lpPkts)
context = TABLET_FindOpenContext(hCtx); context = TABLET_FindOpenContext(hCtx);
if (context->PacketsQueued == 0) if (!context || context->PacketsQueued == 0)
{ {
LeaveCriticalSection(&csTablet); LeaveCriticalSection(&csTablet);
return 0; return 0;
...@@ -923,7 +952,7 @@ int WINAPI WTDataGet(HCTX hCtx, UINT wBegin, UINT wEnd, ...@@ -923,7 +952,7 @@ int WINAPI WTDataGet(HCTX hCtx, UINT wBegin, UINT wEnd,
context = TABLET_FindOpenContext(hCtx); context = TABLET_FindOpenContext(hCtx);
if (context->PacketsQueued == 0) if (!context || context->PacketsQueued == 0)
{ {
LeaveCriticalSection(&csTablet); LeaveCriticalSection(&csTablet);
return 0; return 0;
...@@ -981,7 +1010,7 @@ int WINAPI WTDataPeek(HCTX hCtx, UINT wBegin, UINT wEnd, ...@@ -981,7 +1010,7 @@ int WINAPI WTDataPeek(HCTX hCtx, UINT wBegin, UINT wEnd,
context = TABLET_FindOpenContext(hCtx); context = TABLET_FindOpenContext(hCtx);
if (context->PacketsQueued == 0) if (!context || context->PacketsQueued == 0)
{ {
LeaveCriticalSection(&csTablet); LeaveCriticalSection(&csTablet);
return 0; return 0;
...@@ -1028,7 +1057,7 @@ BOOL WINAPI WTQueuePacketsEx(HCTX hCtx, UINT *lpOld, UINT *lpNew) ...@@ -1028,7 +1057,7 @@ BOOL WINAPI WTQueuePacketsEx(HCTX hCtx, UINT *lpOld, UINT *lpNew)
context = TABLET_FindOpenContext(hCtx); context = TABLET_FindOpenContext(hCtx);
if (context->PacketsQueued) if (context && context->PacketsQueued)
{ {
*lpOld = context->PacketQueue[0].pkSerialNumber; *lpOld = context->PacketQueue[0].pkSerialNumber;
*lpNew = context->PacketQueue[context->PacketsQueued-1].pkSerialNumber; *lpNew = context->PacketQueue[context->PacketsQueued-1].pkSerialNumber;
...@@ -1050,14 +1079,18 @@ BOOL WINAPI WTQueuePacketsEx(HCTX hCtx, UINT *lpOld, UINT *lpNew) ...@@ -1050,14 +1079,18 @@ BOOL WINAPI WTQueuePacketsEx(HCTX hCtx, UINT *lpOld, UINT *lpNew)
int WINAPI WTQueueSizeGet(HCTX hCtx) int WINAPI WTQueueSizeGet(HCTX hCtx)
{ {
LPOPENCONTEXT context; LPOPENCONTEXT context;
int queueSize = 0;
TRACE("(%p)\n", hCtx); TRACE("(%p)\n", hCtx);
if (!hCtx) return 0; if (!hCtx) return 0;
EnterCriticalSection(&csTablet); EnterCriticalSection(&csTablet);
context = TABLET_FindOpenContext(hCtx); context = TABLET_FindOpenContext(hCtx);
if (context)
queueSize = context->QueueSize;
LeaveCriticalSection(&csTablet); LeaveCriticalSection(&csTablet);
return context->QueueSize; return queueSize;
} }
/*********************************************************************** /***********************************************************************
...@@ -1074,6 +1107,11 @@ BOOL WINAPI WTQueueSizeSet(HCTX hCtx, int nPkts) ...@@ -1074,6 +1107,11 @@ BOOL WINAPI WTQueueSizeSet(HCTX hCtx, int nPkts)
EnterCriticalSection(&csTablet); EnterCriticalSection(&csTablet);
context = TABLET_FindOpenContext(hCtx); context = TABLET_FindOpenContext(hCtx);
if (!context)
{
LeaveCriticalSection(&csTablet);
return 0;
}
context->PacketQueue = HeapReAlloc(GetProcessHeap(), 0, context->PacketQueue = HeapReAlloc(GetProcessHeap(), 0,
context->PacketQueue, sizeof(WTPACKET)*nPkts); context->PacketQueue, sizeof(WTPACKET)*nPkts);
......
...@@ -124,23 +124,29 @@ static LRESULT WINAPI TABLET_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, ...@@ -124,23 +124,29 @@ static LRESULT WINAPI TABLET_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
{ {
WTPACKET packet; WTPACKET packet;
LPOPENCONTEXT handler; LPOPENCONTEXT handler;
pGetCurrentPacket(&packet); if (pGetCurrentPacket)
handler = AddPacketToContextQueue(&packet,(HWND)lParam); {
if (handler && handler->context.lcOptions & CXO_MESSAGES) pGetCurrentPacket(&packet);
TABLET_PostTabletMessage(handler, _WT_PACKET(handler->context.lcMsgBase), handler = AddPacketToContextQueue(&packet,(HWND)lParam);
(WPARAM)packet.pkSerialNumber, if (handler && handler->context.lcOptions & CXO_MESSAGES)
(LPARAM)handler->handle, FALSE); TABLET_PostTabletMessage(handler, _WT_PACKET(handler->context.lcMsgBase),
(WPARAM)packet.pkSerialNumber,
(LPARAM)handler->handle, FALSE);
}
break; break;
} }
case WT_PROXIMITY: case WT_PROXIMITY:
{ {
WTPACKET packet; WTPACKET packet;
LPOPENCONTEXT handler; LPOPENCONTEXT handler;
pGetCurrentPacket(&packet); if (pGetCurrentPacket)
handler = AddPacketToContextQueue(&packet,(HWND)wParam); {
if (handler) pGetCurrentPacket(&packet);
TABLET_PostTabletMessage(handler, WT_PROXIMITY, handler = AddPacketToContextQueue(&packet,(HWND)wParam);
(WPARAM)handler->handle, lParam, TRUE); if (handler)
TABLET_PostTabletMessage(handler, WT_PROXIMITY,
(WPARAM)handler->handle, lParam, TRUE);
}
break; break;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment