mirror of
https://github.com/clearlinux/graphene.git
synced 2026-10-03 23:48:19 +00:00
[Linux/SGX PAL] Check NULL handles in DkObjectsWaitAny()
This commit is contained in:
committed by
Chia-Che Tsai
parent
0377bc4b8a
commit
e8f334b220
+1
-1
@@ -89,7 +89,7 @@ DkObjectsWaitAny (PAL_NUM count, PAL_HANDLE * handleArray, PAL_NUM timeout)
|
||||
|
||||
for (int i = 0 ; i < count ; i++)
|
||||
// We modify the caller's handleArray?
|
||||
if (UNKNOWN_HANDLE(handleArray[i]))
|
||||
if (handleArray[i] && UNKNOWN_HANDLE(handleArray[i]))
|
||||
handleArray[i] = NULL;
|
||||
|
||||
PAL_HANDLE polled = NULL;
|
||||
|
||||
@@ -95,7 +95,7 @@ static int _DkObjectWaitOne (PAL_HANDLE handle, uint64_t timeout)
|
||||
|
||||
const struct handle_ops * ops = HANDLE_OPS(handle);
|
||||
|
||||
if (!ops->wait)
|
||||
if (!ops || !ops->wait)
|
||||
return -PAL_ERROR_NOTSUPPORT;
|
||||
|
||||
return ops->wait(handle, timeout);
|
||||
@@ -110,8 +110,15 @@ int _DkObjectsWaitAny (int count, PAL_HANDLE * handleArray, uint64_t timeout,
|
||||
return 0;
|
||||
|
||||
if (count == 1) {
|
||||
*polled = handleArray[0];
|
||||
return _DkObjectWaitOne(handleArray[0], timeout);
|
||||
// It is possible to have NULL pointers in the handle array.
|
||||
// In this case, assume nothing is polled.
|
||||
if (!handleArray[0])
|
||||
return -PAL_ERROR_TRYAGAIN;
|
||||
|
||||
int rv = _DkObjectWaitOne(handleArray[0], timeout);
|
||||
if (rv == 0)
|
||||
*polled = handleArray[0];
|
||||
return rv;
|
||||
}
|
||||
|
||||
int i, j, ret, maxfds = 0, nfds = 0;
|
||||
|
||||
@@ -117,7 +117,7 @@ static int _DkObjectWaitOne (PAL_HANDLE handle, uint64_t timeout)
|
||||
|
||||
const struct handle_ops * ops = HANDLE_OPS(handle);
|
||||
|
||||
if (!ops->wait)
|
||||
if (!ops || !ops->wait)
|
||||
return -PAL_ERROR_NOTSUPPORT;
|
||||
|
||||
return ops->wait(handle, timeout);
|
||||
@@ -132,6 +132,11 @@ int _DkObjectsWaitAny (int count, PAL_HANDLE * handleArray, uint64_t timeout,
|
||||
return 0;
|
||||
|
||||
if (count == 1) {
|
||||
// It is possible to have NULL pointers in the handle array.
|
||||
// In this case, assume nothing is polled.
|
||||
if (!handleArray[0])
|
||||
return -PAL_ERROR_TRYAGAIN;
|
||||
|
||||
int rv = _DkObjectWaitOne(handleArray[0], timeout);
|
||||
if (rv == 0)
|
||||
*polled = handleArray[0];
|
||||
|
||||
Reference in New Issue
Block a user