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:
parent
d7f58f7ea7
commit
2aa4cf57ed
|
@ -1552,28 +1552,16 @@ pgp_update_binary(sc_card_t *card, unsigned int idx,
|
||||||
{
|
{
|
||||||
struct pgp_priv_data *priv = DRVDATA(card);
|
struct pgp_priv_data *priv = DRVDATA(card);
|
||||||
struct blob *blob = priv->current;
|
struct blob *blob = priv->current;
|
||||||
u8 *alldata;
|
|
||||||
size_t allength;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
LOG_FUNC_CALLED(card->ctx);
|
LOG_FUNC_CALLED(card->ctx);
|
||||||
|
|
||||||
/* We will use PUT DATA to write to DO.
|
/* We will use PUT DATA to write to DO.
|
||||||
* This command does not support index, so we will write the overall data,
|
* As PUT DATA does not support idx, we don't either */
|
||||||
* in which the part before idx is get from old content of DO */
|
if (idx > 0)
|
||||||
allength = idx + count;
|
LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
|
||||||
alldata = calloc(allength, 1);
|
|
||||||
if (alldata == NULL)
|
|
||||||
LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
|
|
||||||
|
|
||||||
/* Copy the part before idx */
|
r = pgp_put_data(card, blob->id, buf, count);
|
||||||
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);
|
|
||||||
|
|
||||||
LOG_FUNC_RETURN(card->ctx, r);
|
LOG_FUNC_RETURN(card->ctx, r);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue