Skip to content

Commit

Permalink
FW-880. OSCORE responses may contain empty OSCOR option value.
Browse files Browse the repository at this point in the history
  • Loading branch information
malishav committed Jul 1, 2020
1 parent 91795b4 commit 2c73cad
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions openweb/opencoap/oscore.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,17 +420,27 @@ owerror_t oscore_parse_compressed_COSE(uint8_t *buffer,
uint8_t **kid,
uint8_t *kidLen)
{
uint8_t tmp[0];
uint8_t *ptr;
uint8_t index;
uint8_t n;
uint8_t k;
uint8_t h;
uint8_t reserved;

if (bufferLen == 0) {
tmp[0] = 0x00;
ptr = tmp;
bufferLen = 1;
} else {
ptr = buffer;
}

index = 0;
n = (buffer[index] >> 0) & 0x07;
k = (buffer[index] >> 3) & 0x01;
h = (buffer[index] >> 4) & 0x01;
reserved = (buffer[index] >> 5) & 0x07;
n = (ptr[index] >> 0) & 0x07;
k = (ptr[index] >> 3) & 0x01;
h = (ptr[index] >> 4) & 0x01;
reserved = (ptr[index] >> 5) & 0x07;

if (reserved) {
return E_FAIL;
Expand All @@ -441,23 +451,23 @@ owerror_t oscore_parse_compressed_COSE(uint8_t *buffer,
if (n > 2) {
return 0;
} else if (n == 1) {
*sequenceNumber = buffer[index];
*sequenceNumber = ptr[index];
index++;
} else if (n == 2) {
*sequenceNumber = packetfunctions_ntohs(&buffer[index]);
*sequenceNumber = packetfunctions_ntohs(&ptr[index]);
index += 2;
}

if (h) {
*kidContextLen = buffer[index];
*kidContextLen = ptr[index];
index++;
*kidContext = &buffer[index];
*kidContext = &ptr[index];
index += *kidContextLen;
}

if (k) {
*kidLen = bufferLen - index;
*kid = (*kidLen == 0) ? NULL : &buffer[index];
*kid = (*kidLen == 0) ? NULL : &ptr[index];
index += *kidLen;
}

Expand Down

0 comments on commit 2c73cad

Please sign in to comment.