[nrf528xx] check for otPlatEntropyGet() reentrancy (#3842)

This commit is contained in:
Kamil Sroka
2019-05-20 13:49:21 -07:00
committed by Jonathan Hui
parent f2b19befb1
commit 607f7711e6
2 changed files with 15 additions and 0 deletions
+7
View File
@@ -37,6 +37,7 @@
#include <openthread-core-config.h>
#include <openthread/config.h>
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -50,6 +51,7 @@
static uint8_t sBuffer[RNG_BUFFER_SIZE];
static volatile uint32_t sReadPosition;
static volatile uint32_t sWritePosition;
static volatile bool sEntropyGetEntered;
static inline uint32_t bufferCount(void)
{
@@ -176,6 +178,9 @@ otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength)
uint8_t copyLength;
uint16_t index = 0;
assert(!sEntropyGetEntered);
sEntropyGetEntered = true;
otEXPECT_ACTION(aOutput && aOutputLength, error = OT_ERROR_INVALID_ARGS);
do
@@ -201,5 +206,7 @@ otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength)
} while (index < aOutputLength);
exit:
sEntropyGetEntered = false;
return error;
}
+8
View File
@@ -37,6 +37,7 @@
#include <openthread-core-config.h>
#include <openthread/config.h>
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -45,6 +46,8 @@
#include "platform-nrf5.h"
static volatile bool sEntropyGetEntered;
#if SOFTDEVICE_PRESENT
#include "softdevice.h"
#else
@@ -193,6 +196,9 @@ otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength)
uint8_t copyLength;
uint16_t index = 0;
assert(!sEntropyGetEntered);
sEntropyGetEntered = true;
otEXPECT_ACTION(aOutput && aOutputLength, error = OT_ERROR_INVALID_ARGS);
do
@@ -228,5 +234,7 @@ otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength)
} while (index < aOutputLength);
exit:
sEntropyGetEntered = false;
return error;
}