mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-09 12:54:23 +01:00
ecc-sos,agent: Fix sexp parsing of private key.
* agent/sexp-secret.c (fixup_when_ecc_private_key): Correctly parse SEXP. Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
5f3fcb579f
commit
d1af7b781c
@ -42,6 +42,7 @@ fixup_when_ecc_private_key (unsigned char *buf, size_t buflen)
|
|||||||
if (*s != '(')
|
if (*s != '(')
|
||||||
return gpg_error (GPG_ERR_UNKNOWN_SEXP);
|
return gpg_error (GPG_ERR_UNKNOWN_SEXP);
|
||||||
s++;
|
s++;
|
||||||
|
n = snext (&s);
|
||||||
if (!smatch (&s, n, "ecc"))
|
if (!smatch (&s, n, "ecc"))
|
||||||
return buflen;
|
return buflen;
|
||||||
|
|
||||||
@ -54,12 +55,13 @@ fixup_when_ecc_private_key (unsigned char *buf, size_t buflen)
|
|||||||
return gpg_error (GPG_ERR_INV_SEXP);
|
return gpg_error (GPG_ERR_INV_SEXP);
|
||||||
if (n == 1 && *s == 'd')
|
if (n == 1 && *s == 'd')
|
||||||
{
|
{
|
||||||
const unsigned char *s0;
|
unsigned char *s0;
|
||||||
size_t n0 = n;
|
size_t n0;
|
||||||
|
|
||||||
s += n;
|
s += n;
|
||||||
s0 = s;
|
s0 = (unsigned char *)s;
|
||||||
n = snext (&s);
|
n = snext (&s);
|
||||||
|
n0 = s - s0;
|
||||||
|
|
||||||
if (!n)
|
if (!n)
|
||||||
return gpg_error (GPG_ERR_INV_SEXP);
|
return gpg_error (GPG_ERR_INV_SEXP);
|
||||||
@ -72,8 +74,9 @@ fixup_when_ecc_private_key (unsigned char *buf, size_t buflen)
|
|||||||
|
|
||||||
n--;
|
n--;
|
||||||
buflen--;
|
buflen--;
|
||||||
numsize = snprintf (s0, s-s0, "%u:", (unsigned int)n);
|
numsize = snprintf (s0, s-s0+1, "%u:", (unsigned int)n);
|
||||||
memmove (s0+numsize, s+1, buflen - (s - buf) - 1);
|
memmove (s0+numsize, s+1, buflen - (s - buf));
|
||||||
|
memset (s0+numsize+buflen - (s - buf), 0, (n0 - numsize) + 1);
|
||||||
buflen -= (n0 - numsize);
|
buflen -= (n0 - numsize);
|
||||||
s = s0+numsize+n;
|
s = s0+numsize+n;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user