Skip to content

Commit dd275fc

Browse files
fix(driver/apdu/pcsc): broke device select logic (#414)
* Fix condition to check part_name in reader * Refactor condition to simplify reader check * cleanup skip on reader id and/or name mismatch * Refactor condition with suggestions from the PR * Refactor condition so the ignored reader names are only checked if no reader name was provided via env var * Update driver/apdu/pcsc.c Co-authored-by: Coelacanthus <uwu@coelacanthus.name> * Format code via clang-format --------- Co-authored-by: Coelacanthus <uwu@coelacanthus.name>
1 parent cc60e61 commit dd275fc

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

driver/apdu/pcsc.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,29 @@ static int pcsc_iter_reader(struct pcsc_userdata *userdata,
115115
static int pcsc_open_hCard_iter(struct pcsc_userdata *userdata, const int index, const char *reader, void *context) {
116116
DWORD dwActiveProtocol;
117117

118+
// check id env var
118119
const int id = getenv_or_default(ENV_DRV_IFID, (int)-1);
119-
if (id != -1 && id != index) {
120-
const char *part_name = getenv(ENV_DRV_NAME);
121-
if (part_name != NULL && strstr(reader, part_name) == NULL) {
122-
return 0;
120+
if (id >= 0) {
121+
if (id != index) {
122+
return 0; // skip non-matching reader ids
123+
}
124+
goto matched;
125+
}
126+
127+
// check name env var
128+
const char *part_name = getenv(ENV_DRV_NAME);
129+
if (part_name != NULL) {
130+
if (strstr(reader, part_name) == NULL) {
131+
return 0; // skip non-matching reader names
123132
}
133+
goto matched;
124134
}
125135

126136
if (is_ignored_reader_name(reader)) {
127137
return 0; // skip ignored reader names
128138
}
129139

140+
matched: {} // Workaround for label followed by a declaration in Clang (before C23)
130141
const int ret = SCardConnect(userdata->ctx, reader, SCARD_SHARE_EXCLUSIVE, SCARD_PROTOCOL_T0, &userdata->hCard,
131142
&dwActiveProtocol);
132143
if (ret != SCARD_S_SUCCESS) {

0 commit comments

Comments
 (0)