aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2014-01-15 15:07:05 +0000
committerDavid Howells <dhowells@redhat.com>2014-01-15 15:07:05 +0000
commita6523da06977c3ed4d288f533dc58250a4e69189 (patch)
tree541c72d829031b8f6beb7592e3947f2495435786
parent491cdcaefc3a689e9f5c256373fef9dfd2c4c145 (diff)
downloadkeyutils-a6523da06977c3ed4d288f533dc58250a4e69189.tar.gz
Use keyctl_describe_alloc() in dump_key_tree_aux()
Use the keyctl_describe_alloc() library function in dump_key_tree_aux() in the keyctl program rather than open coding it. Signed-off-by: David Howells <dhowells@redhat.com>
-rw-r--r--keyctl.c21
1 files changed, 2 insertions, 19 deletions
diff --git a/keyctl.c b/keyctl.c
index 4cc6097..3325cd6 100644
--- a/keyctl.c
+++ b/keyctl.c
@@ -1684,7 +1684,7 @@ static int dump_key_tree_aux(key_serial_t key, int depth, int more, int hex_key_
static char dumpindent[64];
key_serial_t *pk;
key_perm_t perm;
- size_t ringlen, desclen;
+ size_t ringlen;
void *payload;
char *desc, type[255], pretty_mask[9];
int uid, gid, ret, n, dpos, rdepth, kcount = 0;
@@ -1692,30 +1692,13 @@ static int dump_key_tree_aux(key_serial_t key, int depth, int more, int hex_key_
if (depth > 8 * 4)
return 0;
- /* find out how big this key's description is */
- ret = keyctl_describe(key, NULL, 0);
- if (ret < 0) {
- printf("%d: key inaccessible (%m)\n", key);
- return 0;
- }
- desclen = ret + 1;
-
- desc = malloc(desclen);
- if (!desc)
- error("malloc");
-
/* read the description */
- ret = keyctl_describe(key, desc, desclen);
+ ret = keyctl_describe_alloc(key, &desc);
if (ret < 0) {
printf("%d: key inaccessible (%m)\n", key);
- free(desc);
return 0;
}
- desclen = ret < desclen ? ret : desclen;
-
- desc[desclen] = 0;
-
/* parse */
type[0] = 0;
uid = 0;