Skip to content

Commit 122b439

Browse files
Merge pull request #2 from gxcreator/fix_transports_parsing
fix(cred_mgmt): check array bounds when populating credentialId.trans…
2 parents 0ed3c4a + 3e43e8b commit 122b439

4 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/fido/cbor_cred_mgmt.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ int cbor_cred_mgmt(const uint8_t *data, size_t len) {
7979
if (strcmp(_fd3, "transports") == 0) {
8080
CBOR_PARSE_ARRAY_START(_f3, 4)
8181
{
82+
if (credentialId.transports_len >= MAX_TRANSPORT_COUNT) {
83+
CBOR_ERROR(CTAP2_ERR_LIMIT_EXCEEDED);
84+
}
8285
CBOR_FIELD_GET_TEXT(credentialId.transports[credentialId.transports_len], 4);
8386
credentialId.transports_len++;
8487
}

src/fido/cbor_get_assertion.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ int cbor_get_assertion(const uint8_t *data, size_t len, bool next) {
124124
else if (val_u == 0x03) { // excludeList
125125
CBOR_PARSE_ARRAY_START(_f1, 2)
126126
{
127+
if (allowList_len >= MAX_CREDENTIAL_COUNT_IN_LIST) {
128+
CBOR_ERROR(CTAP2_ERR_LIMIT_EXCEEDED);
129+
}
127130
PublicKeyCredentialDescriptor *pc = &allowList[allowList_len];
128131
CBOR_PARSE_MAP_START(_f2, 3)
129132
{
@@ -133,6 +136,9 @@ int cbor_get_assertion(const uint8_t *data, size_t len, bool next) {
133136
if (strcmp(_fd3, "transports") == 0) {
134137
CBOR_PARSE_ARRAY_START(_f3, 4)
135138
{
139+
if (pc->transports_len >= MAX_TRANSPORT_COUNT) {
140+
CBOR_ERROR(CTAP2_ERR_LIMIT_EXCEEDED);
141+
}
136142
CBOR_FIELD_GET_TEXT(pc->transports[pc->transports_len], 4);
137143
pc->transports_len++;
138144
}
@@ -481,6 +487,9 @@ int cbor_get_assertion(const uint8_t *data, size_t len, bool next) {
481487
}
482488
numberOfCredentialsx = numberOfCredentials;
483489
datax = (uint8_t *) calloc(1, len);
490+
if (datax == NULL) {
491+
CBOR_ERROR(CTAP1_ERR_OTHER);
492+
}
484493
memcpy(datax, data, len);
485494
lenx = len;
486495
flagsx = flags;
@@ -608,6 +617,9 @@ int cbor_get_assertion(const uint8_t *data, size_t len, bool next) {
608617

609618
size_t aut_data_len = 32 + 1 + 4 + ext_len;
610619
aut_data = (uint8_t *) calloc(1, aut_data_len + clientDataHash.len);
620+
if (aut_data == NULL) {
621+
CBOR_ERROR(CTAP1_ERR_OTHER);
622+
}
611623
uint8_t *pa = aut_data;
612624
memcpy(pa, rp_id_hash, 32); pa += 32;
613625
*pa++ = flags;

src/fido/cbor_make_credential.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ int cbor_make_credential(const uint8_t *data, size_t len) {
9292
else if (val_u == 0x04) { // pubKeyCredParams
9393
CBOR_PARSE_ARRAY_START(_f1, 2)
9494
{
95+
if (pubKeyCredParams_len >= MAX_CREDENTIAL_COUNT_IN_LIST) {
96+
CBOR_ERROR(CTAP2_ERR_LIMIT_EXCEEDED);
97+
}
9598
PublicKeyCredentialParameters *pk = &pubKeyCredParams[pubKeyCredParams_len];
9699
CBOR_PARSE_MAP_START(_f2, 3)
97100
{
@@ -107,6 +110,9 @@ int cbor_make_credential(const uint8_t *data, size_t len) {
107110
else if (val_u == 0x05) { // excludeList
108111
CBOR_PARSE_ARRAY_START(_f1, 2)
109112
{
113+
if (excludeList_len >= MAX_CREDENTIAL_COUNT_IN_LIST) {
114+
CBOR_ERROR(CTAP2_ERR_LIMIT_EXCEEDED);
115+
}
110116
PublicKeyCredentialDescriptor *pc = &excludeList[excludeList_len];
111117
CBOR_PARSE_MAP_START(_f2, 3)
112118
{
@@ -116,6 +122,9 @@ int cbor_make_credential(const uint8_t *data, size_t len) {
116122
if (strcmp(_fd3, "transports") == 0) {
117123
CBOR_PARSE_ARRAY_START(_f3, 4)
118124
{
125+
if (pc->transports_len >= MAX_TRANSPORT_COUNT) {
126+
CBOR_ERROR(CTAP2_ERR_LIMIT_EXCEEDED);
127+
}
119128
CBOR_FIELD_GET_TEXT(pc->transports[pc->transports_len], 4);
120129
pc->transports_len++;
121130
}

src/fido/cbor_make_credential.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ typedef struct PublicKeyCredentialParameters {
4040
int64_t alg;
4141
} PublicKeyCredentialParameters;
4242

43+
#define MAX_TRANSPORT_COUNT 8
44+
4345
typedef struct PublicKeyCredentialDescriptor {
4446
CborCharString type;
4547
CborByteString id;
46-
CborCharString transports[8];
48+
CborCharString transports[MAX_TRANSPORT_COUNT];
4749
size_t transports_len;
4850
} PublicKeyCredentialDescriptor;
4951

0 commit comments

Comments
 (0)