Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reader initialization without SCardControl #3007

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix reader initialization without SCardControl
fixes #3006
  • Loading branch information
frankmorgner committed Feb 1, 2024
commit a93fb847edcd33473eed884cfe908ce11ed686c4
29 changes: 15 additions & 14 deletions src/libopensc/reader-pcsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ static int pcsc_internal_transmit(sc_reader_t *reader,
struct pcsc_private_data *priv = reader->drv_data;
SCARD_IO_REQUEST sSendPci, sRecvPci;
DWORD dwSendLength, dwRecvLength;
LONG rv;
LONG rv = SCARD_E_INVALID_VALUE;
SCARDHANDLE card;

LOG_FUNC_CALLED(reader->ctx);
Expand All @@ -264,8 +264,10 @@ static int pcsc_internal_transmit(sc_reader_t *reader,
recvbuf, &dwRecvLength);
}
else {
rv = priv->gpriv->SCardControl(card, (DWORD) control, sendbuf, dwSendLength,
recvbuf, dwRecvLength, &dwRecvLength);
if (priv->gpriv->SCardControl != NULL) {
rv = priv->gpriv->SCardControl(card, (DWORD) control, sendbuf, dwSendLength,
recvbuf, dwRecvLength, &dwRecvLength);
}
Jakuje marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -1016,7 +1018,7 @@ static unsigned long part10_detect_pace_capabilities(sc_reader_t *reader, SCARDH
if (!priv)
goto err;

if (priv->pace_ioctl && priv->gpriv) {
if (priv->pace_ioctl && priv->gpriv && priv->gpriv->SCardControl) {
if (SCARD_S_SUCCESS != priv->gpriv->SCardControl(card_handle,
priv->pace_ioctl, pace_capabilities_buf,
sizeof pace_capabilities_buf, rbuf, sizeof(rbuf),
Expand Down Expand Up @@ -1075,7 +1077,7 @@ static size_t part10_detect_max_data(sc_reader_t *reader, SCARDHANDLE card_handl
if (!priv)
goto err;

if (priv->get_tlv_properties && priv->gpriv) {
if (priv->get_tlv_properties && priv->gpriv && priv->gpriv->SCardControl) {
if (SCARD_S_SUCCESS != priv->gpriv->SCardControl(card_handle,
priv->get_tlv_properties, NULL, 0, rbuf, sizeof(rbuf), &rcount)) {
sc_log(reader->ctx, "PC/SC v2 part 10: Get TLV properties failed!");
Expand Down Expand Up @@ -1108,7 +1110,7 @@ static int part10_get_vendor_product(struct sc_reader *reader,
if (!priv)
return SC_ERROR_INVALID_ARGUMENTS;

if (priv->get_tlv_properties && priv->gpriv) {
if (priv->get_tlv_properties && priv->gpriv && priv->gpriv->SCardControl) {
if (SCARD_S_SUCCESS != priv->gpriv->SCardControl(card_handle,
priv->get_tlv_properties, NULL, 0, rbuf, sizeof(rbuf),
&rcount)) {
Expand Down Expand Up @@ -1147,13 +1149,12 @@ static void detect_reader_features(sc_reader_t *reader, SCARDHANDLE card_handle)

sc_log(ctx, "Requesting reader features ... ");

if (gpriv->SCardControl == NULL)
return;

rv = gpriv->SCardControl(card_handle, CM_IOCTL_GET_FEATURE_REQUEST, NULL, 0, buf, sizeof(buf), &rcount);
if (rv != SCARD_S_SUCCESS) {
PCSC_TRACE(reader, "SCardControl failed", rv);
return;
if (gpriv->SCardControl != NULL) {
rv = gpriv->SCardControl(card_handle, CM_IOCTL_GET_FEATURE_REQUEST, NULL, 0, buf, sizeof(buf), &rcount);
if (rv != SCARD_S_SUCCESS) {
PCSC_TRACE(reader, "SCardControl failed", rv);
return;
}
}

if ((rcount % sizeof(PCSC_TLV_STRUCTURE)) != 0
Jakuje marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -1221,7 +1222,7 @@ static void detect_reader_features(sc_reader_t *reader, SCARDHANDLE card_handle)
}

/* Detect display */
if (priv->pin_properties_ioctl) {
if (priv->pin_properties_ioctl && gpriv->SCardControl) {
frankmorgner marked this conversation as resolved.
Show resolved Hide resolved
rcount = sizeof(buf);
rv = gpriv->SCardControl(card_handle, priv->pin_properties_ioctl,
NULL, 0, buf, sizeof(buf), &rcount);
Expand Down
Loading