From c2f02797cdefdce5afd8b29bb8e51d4515a70a96 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 10 Jun 2021 12:43:40 +0200 Subject: [PATCH] scd: Fix serial number detection for Yubikey 5. * scd/app.c (app_new_register): Handle serial number correctly. -- GnuPG-bug-id: 5442 Signed-off-by: NIIBE Yutaka Backported-from-master: c3a9ee0b658887ca9baa4514187b17857fdf6586 --- scd/app.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scd/app.c b/scd/app.c index b1bc35f53..846fc7761 100644 --- a/scd/app.c +++ b/scd/app.c @@ -299,17 +299,18 @@ app_new_register (int slot, ctrl_t ctrl, const char *name, formfactor = (s0 && n == 1)? *s0 : 0; s0 = find_tlv (buf+1, buflen-1, 0x02, &n); /* Serial */ - if (s0 && n >= 4) + if (s0 && n <= 4) { - app->serialno = xtrymalloc (3 + 1 + n); + app->serialno = xtrymalloc (3 + 1 + 4); if (app->serialno) { - app->serialnolen = 3 + 1 + n; + app->serialnolen = 3 + 1 + 4; app->serialno[0] = 0xff; app->serialno[1] = 0x02; app->serialno[2] = 0x0; app->serialno[3] = formfactor; - memcpy (app->serialno + 4, s0, n); + memset (app->serialno + 4, 0, 4 - n); + memcpy (app->serialno + 4 + 4 - n, s0, n); err = app_munge_serialno (app); } }