Skip to content

Commit 7355031

Browse files
committed
PrepareUserAuthRequestEcc Missing Bounds Checks
For agent ECC public key parsing, replaced parsing the data by hand with the GetSkip() and GetStringRef() functions which do bounds checking. Affected function: PrepareUserAuthRequestEcc. Issue: F-526
1 parent 6a89725 commit 7355031

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

src/internal.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14397,26 +14397,36 @@ static int PrepareUserAuthRequestEcc(WOLFSSH* ssh, word32* payloadSz,
1439714397
ret = wc_ecc_init(&keySig->ks.ecc.key);
1439814398

1439914399
if (ret == 0) {
14400-
word32 idx = 0;
14400+
word32 idx;
1440114401
#ifdef WOLFSSH_AGENT
1440214402
if (ssh->agentEnabled) {
14403-
word32 sz;
14404-
const byte* c = (const byte*)authData->sf.publicKey.publicKey;
14403+
const byte* publicKey = NULL;
14404+
word32 publicKeySz;
1440514405

14406-
ato32(c + idx, &sz);
14407-
idx += LENGTH_SZ + sz;
14408-
ato32(c + idx, &sz);
14409-
idx += LENGTH_SZ + sz;
14410-
ato32(c + idx, &sz);
14411-
idx += LENGTH_SZ;
14412-
c += idx;
1441314406
idx = 0;
14414-
14415-
ret = wc_ecc_import_x963(c, sz, &keySig->ks.ecc.key);
14407+
ret = GetSkip((const byte*)authData->sf.publicKey.publicKey,
14408+
authData->sf.publicKey.publicKeySz, &idx);
14409+
if (ret == WS_SUCCESS) {
14410+
ret = GetSkip((const byte*)authData->sf.publicKey.publicKey,
14411+
authData->sf.publicKey.publicKeySz, &idx);
14412+
}
14413+
if (ret == WS_SUCCESS) {
14414+
ret = GetStringRef(&publicKeySz, &publicKey,
14415+
(const byte*)authData->sf.publicKey.publicKey,
14416+
authData->sf.publicKey.publicKeySz, &idx);
14417+
}
14418+
if (ret == WS_SUCCESS) {
14419+
ret = wc_ecc_import_x963(publicKey, publicKeySz,
14420+
&keySig->ks.ecc.key);
14421+
}
14422+
if (ret == 0) {
14423+
ret = WS_SUCCESS;
14424+
}
1441614425
}
1441714426
else
1441814427
#endif
1441914428
{
14429+
idx = 0;
1442014430
ret = wc_EccPrivateKeyDecode(authData->sf.publicKey.privateKey,
1442114431
&idx, &keySig->ks.ecc.key,
1442214432
authData->sf.publicKey.privateKeySz);
@@ -14426,6 +14436,9 @@ static int PrepareUserAuthRequestEcc(WOLFSSH* ssh, word32* payloadSz,
1442614436
authData->sf.publicKey.privateKey,
1442714437
authData->sf.publicKey.privateKeySz, &idx);
1442814438
}
14439+
else {
14440+
ret = WS_ECC_E;
14441+
}
1442914442
}
1443014443
}
1443114444

0 commit comments

Comments
 (0)