Repository navigation
Fix MinGW build bug and ACR122U PC/SC reconnect issue on Windows - #765
Open
doomfrawen wants to merge 3 commits into
Open
doomfrawen wants to merge 3 commits into
doomfrawen wants to merge 3 commits into
Conversation
- contrib/win32/stdlib.c: setenv()/unsetenv() declared 'char *str[32]' (an array of 32 uninitialized pointers) instead of 'char str[32]' (a buffer). Under older GCC this only warned; GCC >= 14 rejects it as an incompatible pointer type, and even when it compiles the original code writes through a garbage pointer. - libnfc/drivers/acr122_pcsc.c: acr122_pcsc_close() disconnected with SCARD_LEAVE_CARD, which on an ACR122U talking through Windows' inbox CCID driver (WUDFUsbccidDriver) leaves the reader's internal session state such that the *next* SCardConnect from any process fails with 'No ACR122 firmware received' until the device is physically replugged. Disconnecting with SCARD_UNPOWER_CARD forces a clean depower/reset of the card interface on close, matching what a physical replug does, and the reader is immediately usable again by the next open.
maksimtech
added a commit
to maksimtech/libnfc
that referenced
this pull request
Oct 22, 2026
The Windows job reaches the compiler and fails in contrib/win32/stdlib.c (char *str[32] passed to strcpy, nfc-tools#765). Keep it visible but non-blocking until that fix is merged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
maksimtech
added a commit
to maksimtech/libnfc
that referenced
this pull request
Oct 22, 2026
contrib/win32/stdlib.c declared char *str[32], an array of pointers, and passed it to strcpy/putenv: an error with current GCC, and a 32-byte buffer could overflow with a longer name and value. Use _putenv_s, which copies its arguments, and return what POSIX specifies when overwrite is 0 and the variable already exists. Include <string.h> and <stdlib.h> explicitly. Refs nfc-tools#765 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Tested this on a clean Windows runner (MSYS2 MinGW64, GCC 16.2), and the
I fixed it with I did not cover the (Test runs done with Claude Code assistance; I reviewed the results.) |
Address the overflow and overwrite=0 feedback on nfc-tools#765, using the _putenv_s approach suggested in maksimtech#2. Validate arguments before calling the CRT and preserve void unsetenv. Add hardware-free regression checks for MinGW64 and UCRT64, and limit the existing ACR122 PC/SC power-down change to Windows. Assisted-by: Codex
doomfrawen
added a commit
to doomfrawen/mfoc-hardnested
that referenced
this pull request
Nov 19, 2026
Apply the _putenv_s approach discussed in nfc-tools/libnfc#765 and maksimtech/libnfc#2 to the same compatibility helpers here. Return success when overwrite=0 preserves an existing value and reject invalid arguments before calling the CRT. Add hardware-free Windows regression checks for MinGW64 and UCRT64. Assisted-by: Codex
The environment helpers use only stdlib.h and string.h. Including the broad platform header redefines modern MinGW errno constants and fails the new warnings-as-errors compile check.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've updated the Windows environment helpers and limited the ACR122U power-down change to Windows.
setenv()andunsetenv()with_putenv_s, following Maksim's feedback and the approach in maksimtech/libnfc#2. An existing variable withoverwrite=0now returns success without changing its value. I also added checks for invalid names and null values before calling the CRT, while keeping the existing voidunsetenv()signature and Windows empty-value removal behavior.SCARD_UNPOWER_CARDon close to_WIN32. Other platforms still useSCARD_LEAVE_CARD.For the reader issue, I was using a genuine ACS ACR122U on Windows 10 with the inbox CCID driver (
WUDFUsbccidDriver). I built libnfc through MSYS2 MinGW64 with-DLIBNFC_DRIVER_ACR122_PCSC=ON. On subsequent opens, I gotNo ACR122 firmware received, Error: 00000001and had to unplug and reconnect the reader before I could use it again. Powering down the card on close allowed subsequent runs. The error comes from the firmware request, so I can't conclude from that alone thatSCardConnectfailed. Microsoft documentsSCARD_UNPOWER_CARDas powering down the card; that isn't the same as unplugging the USB reader.Validation at
0154327:-Wall -Wextra -Werror.git diff --check, which passed.I haven't retested the reader for this update, and I don't think I still have the original before/after logs. I haven't included the exact Windows build or driver/firmware versions. The tests I've added cover the Windows environment helpers, not the full library or NFC hardware. The upstream workflow still needs maintainer approval.