crypto/random_pool.c: fix getrandom() when thread calling it gets canceled

Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
This commit is contained in:
Juha Niskanen 2020-12-08 18:20:53 +02:00 committed by Xiang Xiao
parent 6244924c3e
commit 84bbc9f5fd

View File

@ -55,11 +55,11 @@
#include <nuttx/crypto/blake2s.h> #include <nuttx/crypto/blake2s.h>
/**************************************************************************** /****************************************************************************
* Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#ifndef MIN #ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b)) # define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif #endif
#define ROTL_32(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) ) #define ROTL_32(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) )
@ -565,10 +565,19 @@ void getrandom(FAR void *bytes, size_t nbytes)
{ {
int ret; int ret;
ret = nxsem_wait_uninterruptible(&g_rng.rd_sem); do
if (ret >= 0)
{ {
ret = nxsem_wait_uninterruptible(&g_rng.rd_sem);
/* The only possible error should be if we were awakened by
* thread cancellation. At this point, we must continue to acquire
* the semaphore anyway.
*/
DEBUGASSERT(ret == OK || ret == -ECANCELED);
}
while (ret < 0);
rng_buf_internal(bytes, nbytes); rng_buf_internal(bytes, nbytes);
nxsem_post(&g_rng.rd_sem); nxsem_post(&g_rng.rd_sem);
}
} }