Skip to content

Commit 1f24ace

Browse files
authored
[spinel] fix writeable size in spinel logging (openthread#13094)
There exists a NULL-byte OOB in the spinel logging. The initial stack buffer is initialized with an extra byte for the NULL-byte. However, the full size is passed into `spinel_datatype_unpack_in_place()` which interprets it as the valid writable size (`require_action(NULL != block_len_ptr && *block_len_ptr >= block_len, bail, (ret = -1, errno = EINVAL));`). When `block_len` is the length of the buffer, the NULL-byte write after the function call will be OOB.
1 parent d011ade commit 1f24ace

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/lib/spinel/logger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ void Logger::LogSpinelFrame(const uint8_t *aFrame, uint16_t aLength, bool aTx)
524524
case SPINEL_PROP_STREAM_DEBUG:
525525
{
526526
char debugString[OPENTHREAD_LIB_SPINEL_NCP_LOG_MAX_SIZE + 1];
527-
spinel_size_t stringLength = sizeof(debugString);
527+
spinel_size_t stringLength = sizeof(debugString) - 1;
528528

529529
unpacked = spinel_datatype_unpack_in_place(data, len, SPINEL_DATATYPE_DATA_S, debugString, &stringLength);
530530
assert(stringLength < sizeof(debugString));

src/lib/spinel/radio_spinel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ void RadioSpinel::HandleValueIs(spinel_prop_key_t aKey, const uint8_t *aBuffer,
556556
else if (aKey == SPINEL_PROP_STREAM_DEBUG)
557557
{
558558
char logStream[OPENTHREAD_CONFIG_NCP_SPINEL_LOG_MAX_SIZE + 1];
559-
unsigned int len = sizeof(logStream);
559+
unsigned int len = sizeof(logStream) - 1;
560560

561561
unpacked = spinel_datatype_unpack_in_place(aBuffer, aLength, SPINEL_DATATYPE_DATA_S, logStream, &len);
562562
assert(len < sizeof(logStream));

0 commit comments

Comments
 (0)