Skip to content

Commit 8039e88

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 27f3b06 commit 8039e88

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

src/internal.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14393,26 +14393,32 @@ static int PrepareUserAuthRequestEcc(WOLFSSH* ssh, word32* payloadSz,
1439314393
ret = wc_ecc_init(&keySig->ks.ecc.key);
1439414394

1439514395
if (ret == 0) {
14396-
word32 idx = 0;
14396+
word32 idx;
1439714397
#ifdef WOLFSSH_AGENT
1439814398
if (ssh->agentEnabled) {
1439914399
word32 sz;
1440014400
const byte* c = (const byte*)authData->sf.publicKey.publicKey;
1440114401

14402-
ato32(c + idx, &sz);
14403-
idx += LENGTH_SZ + sz;
14404-
ato32(c + idx, &sz);
14405-
idx += LENGTH_SZ + sz;
14406-
ato32(c + idx, &sz);
14407-
idx += LENGTH_SZ;
14408-
c += idx;
1440914402
idx = 0;
14410-
14411-
ret = wc_ecc_import_x963(c, sz, &keySig->ks.ecc.key);
14403+
ret = GetSkip(c, authData->sf.publicKey.publicKeySz, &idx);
14404+
if (ret == WS_SUCCESS) {
14405+
ret = GetSkip(c, authData->sf.publicKey.publicKeySz, &idx);
14406+
}
14407+
if (ret == WS_SUCCESS) {
14408+
ret = GetStringRef(&sz, &c, c,
14409+
authData->sf.publicKey.publicKeySz, &idx);
14410+
}
14411+
if (ret == WS_SUCCESS) {
14412+
ret = wc_ecc_import_x963(c, sz, &keySig->ks.ecc.key);
14413+
}
14414+
if (ret == 0) {
14415+
ret = WS_SUCCESS;
14416+
}
1441214417
}
1441314418
else
1441414419
#endif
1441514420
{
14421+
idx = 0;
1441614422
ret = wc_EccPrivateKeyDecode(authData->sf.publicKey.privateKey,
1441714423
&idx, &keySig->ks.ecc.key,
1441814424
authData->sf.publicKey.privateKeySz);
@@ -14422,6 +14428,9 @@ static int PrepareUserAuthRequestEcc(WOLFSSH* ssh, word32* payloadSz,
1442214428
authData->sf.publicKey.privateKey,
1442314429
authData->sf.publicKey.privateKeySz, &idx);
1442414430
}
14431+
else {
14432+
ret = WS_ECC_E;
14433+
}
1442514434
}
1442614435
}
1442714436

0 commit comments

Comments
 (0)