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.
This commit is contained in:
Peter Marschall 2012-06-08 10:18:46 +02:00
parent d7f58f7ea7
commit 2aa4cf57ed
1 changed files with 4 additions and 16 deletions

View File

@ -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);
}