[Linux/SGX PAL] Check NULL handles in DkObjectsWaitAny()

This commit is contained in:
Chia-Che Tsai
2018-12-03 15:07:38 -08:00
committed by Chia-Che Tsai
parent 0377bc4b8a
commit e8f334b220
3 changed files with 17 additions and 5 deletions
+1 -1
View File
@@ -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;
+10 -3
View File
@@ -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;
+6 -1
View File
@@ -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];