Skip to content

Commit 6a3e97d

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 6638c01 commit 6a3e97d

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
@@ -14400,19 +14400,32 @@ static int PrepareUserAuthRequestEcc(WOLFSSH* ssh, word32* payloadSz,
1440014400
word32 idx = 0;
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;
14413-
idx = 0;
14414-
14415-
ret = wc_ecc_import_x963(c, sz, &keySig->ks.ecc.key);
14406+
ret = GetSkip((const byte*)authData->sf.publicKey.publicKey,
14407+
authData->sf.publicKey.publicKeySz, &idx);
14408+
if (ret == WS_SUCCESS) {
14409+
ret = GetSkip((const byte*)authData->sf.publicKey.publicKey,
14410+
authData->sf.publicKey.publicKeySz, &idx);
14411+
}
14412+
if (ret == WS_SUCCESS) {
14413+
ret = GetStringRef(&publicKeySz, &publicKey,
14414+
(const byte*)authData->sf.publicKey.publicKey,
14415+
authData->sf.publicKey.publicKeySz, &idx);
14416+
}
14417+
if (ret == WS_SUCCESS) {
14418+
ret = wc_ecc_import_x963(publicKey, publicKeySz,
14419+
&keySig->ks.ecc.key);
14420+
}
14421+
if (ret != 0) {
14422+
WLOG(WS_LOG_ERROR,
14423+
"wc_ecc_import_x963 failed, ret = %d", ret);
14424+
ret = WS_ECC_E;
14425+
}
14426+
else {
14427+
ret = WS_SUCCESS;
14428+
}
1441614429
}
1441714430
else
1441814431
#endif

0 commit comments

Comments
 (0)