From 2aa4cf57eda8bd81b6d5558247cdf3d7fd6509c9 Mon Sep 17 00:00:00 2001 From: Peter Marschall Date: Fri, 8 Jun 2012 10:18:46 +0200 Subject: [PATCH] OpenPGP: simplify pgp_update_binary() even more Fail on idx > 0 in order to avoid the requirement to read from the DO. The DO may be read-protected, and this might either fail or produce wrong results. --- src/libopensc/card-openpgp.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c index 79a31e54..f862e294 100644 --- a/src/libopensc/card-openpgp.c +++ b/src/libopensc/card-openpgp.c @@ -1552,28 +1552,16 @@ pgp_update_binary(sc_card_t *card, unsigned int idx, { struct pgp_priv_data *priv = DRVDATA(card); struct blob *blob = priv->current; - u8 *alldata; - size_t allength; int r; LOG_FUNC_CALLED(card->ctx); /* We will use PUT DATA to write to DO. - * This command does not support index, so we will write the overall data, - * in which the part before idx is get from old content of DO */ - allength = idx + count; - alldata = calloc(allength, 1); - if (alldata == NULL) - LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY); + * As PUT DATA does not support idx, we don't either */ + if (idx > 0) + LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS); - /* Copy the part before idx */ - if (blob->data) - memcpy(alldata, blob->data, MIN(idx, blob->len)); - /* Copy data need to be written */ - memcpy(alldata+idx, buf, count); - - r = pgp_put_data(card, blob->id, alldata, allength); - free(alldata); + r = pgp_put_data(card, blob->id, buf, count); LOG_FUNC_RETURN(card->ctx, r); }