aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2022-05-26 04:35:33 +0000
committerNIIBE Yutaka <[email protected]>2022-05-26 05:01:03 +0000
commit295a6a7591972442a9ef4f8964baf9cdbe297cdd (patch)
treede6f80335c6fd05c6b6c70caa6b096d8cc70e5b7
parentscd: Return USAGE information for KEYINFO command. (diff)
downloadgnupg-295a6a7591972442a9ef4f8964baf9cdbe297cdd.tar.gz
gnupg-295a6a7591972442a9ef4f8964baf9cdbe297cdd.zip
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 <[email protected]>
-rw-r--r--agent/agent.h1
-rw-r--r--agent/call-scd.c28
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;
+
+ for (s = line; *s && !spacep (s); s++)
+ ;
- keyinfo->idstr = xtrystrdup (line);
+ 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);
}
}