From 0a3bec2c2525935362f87dce93d7df2c8d498498 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Mon, 12 Feb 2018 18:56:58 +0900 Subject: [PATCH] scd: Fix handling for Data Object with no data. * scd/app-openpgp.c (get_cached_data): Return NULL for Data Object with no data. -- When GET_DATA returns no data with success (90 00), this routine firstly returned buffer with length zero, and secondly (with cache) returned NULL, which is inconsistent. Now, it returns NULL for both cases. Signed-off-by: NIIBE Yutaka --- scd/app-openpgp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scd/app-openpgp.c b/scd/app-openpgp.c index c9f2840e6..5b1b0d339 100644 --- a/scd/app-openpgp.c +++ b/scd/app-openpgp.c @@ -348,7 +348,8 @@ get_cached_data (app_t app, int tag, err = iso7816_get_data (app->slot, exmode, tag, &p, &len); if (err) return err; - *result = p; + if (len) + *result = p; *resultlen = len; /* Check whether we should cache this object. */ @@ -370,7 +371,10 @@ get_cached_data (app_t app, int tag, c = xtrymalloc (sizeof *c + len); if (c) { - memcpy (c->data, p, len); + if (len) + memcpy (c->data, p, len); + else + xfree (p); c->length = len; c->tag = tag; c->next = app->app_local->cache;