scd: Fix count_sos_bits handling.

* scd/app-openpgp.c (count_sos_bits): Handle an exceptional case.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2021-03-15 17:00:56 +09:00
parent 373b52e69a
commit f482e4bd12
1 changed files with 3 additions and 3 deletions

View File

@ -723,7 +723,7 @@ count_sos_bits (const unsigned char *a, size_t len)
unsigned int n = len * 8; unsigned int n = len * 8;
int i; int i;
if (*a == 0) if (len == 0 || *a == 0)
return n; return n;
for (i=7; i && !(*a & (1<<i)); i--) for (i=7; i && !(*a & (1<<i)); i--)
@ -912,11 +912,11 @@ store_fpr (app_t app, int keynumber, u32 timestamp, unsigned char *fpr,
*p++ = nbits; *p++ = nbits;
} }
else if (i == 1) else if (i == 1)
{ {
nbits = count_sos_bits (m[i], mlen[i]); nbits = count_sos_bits (m[i], mlen[i]);
*p++ = nbits >> 8; *p++ = nbits >> 8;
*p++ = nbits; *p++ = nbits;
} }
memcpy (p, m[i], mlen[i]); memcpy (p, m[i], mlen[i]);
p += mlen[i]; p += mlen[i];
} }