Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit e4bb58c

Browse files
committed
fix filling out of initresp
1 parent 17d67ff commit e4bb58c

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

u2f-host/devs.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,17 +302,29 @@ init_device (u2fh_devs * devs, struct u2fdevice *dev)
302302
(devs, dev->id, U2FHID_INIT, nonce, sizeof (nonce), resp,
303303
&resplen) == U2FH_OK)
304304
{
305-
U2FHID_INIT_RESP initresp;
306-
if (resplen > sizeof (initresp))
305+
int offs = sizeof (nonce);
306+
/* the response has to be atleast 17 bytes, if it's more we discard that */
307+
if (resplen < 17)
307308
{
308-
return U2FH_MEMORY_ERROR;
309+
return U2FH_SIZE_ERROR;
309310
}
310-
memcpy (&initresp, resp, resplen);
311-
dev->cid = initresp.cid;
312-
dev->versionInterface = initresp.versionInterface;
313-
dev->versionMajor = initresp.versionMajor;
314-
dev->versionMinor = initresp.versionMinor;
315-
dev->capFlags = initresp.capFlags;
311+
312+
/* incoming and outgoing nonce has to match */
313+
if (memcmp (nonce, resp, sizeof (nonce)) != 0)
314+
{
315+
return U2FH_TRANSPORT_ERROR;
316+
}
317+
318+
dev->cid =
319+
resp[offs] << 24 | resp[offs + 1] << 16 | resp[offs +
320+
2] << 8 | resp[offs +
321+
3];
322+
offs += 4;
323+
dev->versionInterface = resp[offs++];
324+
dev->versionMajor = resp[offs++];
325+
dev->versionMinor = resp[offs++];
326+
dev->versionBuild = resp[offs++];
327+
dev->capFlags = resp[offs++];
316328
}
317329
else
318330
{

0 commit comments

Comments
 (0)