From 295a6a7591972442a9ef4f8964baf9cdbe297cdd Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Thu, 26 May 2022 13:35:33 +0900 Subject: [PATCH] agent: Handle USAGE information in KEYINFO. * agent/agent.h (struct card_key_info_s): Add USAGE field. * agent/call-scd.c (card_keyinfo_cb): Parse USAGE field. Allow optional SERIALNO, IDSTR, and USAGE fields. Fix releasing on possible allocation error. -- Signed-off-by: NIIBE Yutaka --- agent/agent.h | 1 + agent/call-scd.c | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/agent/agent.h b/agent/agent.h index f1c9b83b6..d32a756f6 100644 --- a/agent/agent.h +++ b/agent/agent.h @@ -392,6 +392,7 @@ struct card_key_info_s char keygrip[41]; char *serialno; char *idstr; + char *usage; }; /*-- gpg-agent.c --*/ diff --git a/agent/call-scd.c b/agent/call-scd.c index aa8c3eece..91e28e68c 100644 --- a/agent/call-scd.c +++ b/agent/call-scd.c @@ -939,6 +939,7 @@ card_keyinfo_cb (void *opaque, const char *line) int n; struct card_key_info_s **l_p = &parm->list; + /* It's going to append the information at the end. */ while ((*l_p)) l_p = &(*l_p)->next; @@ -976,7 +977,7 @@ card_keyinfo_cb (void *opaque, const char *line) ; if (!n) - goto parm_error; + goto skip; keyinfo->serialno = xtrymalloc (n+1); if (!keyinfo->serialno) @@ -988,18 +989,34 @@ card_keyinfo_cb (void *opaque, const char *line) line = s; if (!*line) - goto parm_error; + goto skip; while (spacep (line)) line++; if (!*line) - goto parm_error; + goto skip; - keyinfo->idstr = xtrystrdup (line); + for (s = line; *s && !spacep (s); s++) + ; + + keyinfo->idstr = xtrymalloc (s - line + 1); if (!keyinfo->idstr) goto alloc_error; + memcpy (keyinfo->idstr, line, s - line); + keyinfo->idstr[s - line] = 0; + while (spacep (s)) + s++; + + if (!*s) + goto skip; + + keyinfo->usage = xtrystrdup (s); + if (!keyinfo->usage) + goto alloc_error; + + skip: *l_p = keyinfo; } else if (keywordlen == 12 && !memcmp (keyword, "PINCACHE_PUT", keywordlen)) @@ -1008,6 +1025,8 @@ card_keyinfo_cb (void *opaque, const char *line) return err; alloc_error: + xfree (keyinfo->serialno); + xfree (keyinfo->idstr); xfree (keyinfo); if (!parm->error) parm->error = gpg_error_from_syserror (); @@ -1031,6 +1050,7 @@ agent_card_free_keyinfo (struct card_key_info_s *l) l_next = l->next; xfree (l->serialno); xfree (l->idstr); + xfree (l->usage); xfree (l); } }