Repository navigation
fix(win32): setenv()/unsetenv() do not compile and can overflow - #2
Merged
Merged
Conversation
Windows lacks setenv() and unsetenv(); contrib/win32/stdlib.c provides them and does not compile with current GCC (char *str[32] passed to strcpy, nfc-tools#765). Add a Windows-only test that builds that file and checks set/unset, the overwrite flag and a long name and value. The Windows CI job no longer ignores failures. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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>
pn53x-diagnose, pn53x-sam and pn53x-tamashell use libnfc internals that the DLL does not export (#3). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
doomfrawen
added a commit
to doomfrawen/libnfc
that referenced
this pull request
Nov 19, 2026
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
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.



Fixes the MinGW build failure that the new Windows CI job exposed. Related upstream PR: nfc-tools#765 (by @doomfrawen), whose
contrib/win32/stdlib.cchange this builds on.Problem
contrib/win32/stdlib.cdeclareschar *str[32](an array of pointers) and passes it tostrcpy/putenv: an error with current GCC (-Wincompatible-pointer-types, fatal since GCC 14). Even with the type fixed, a 32-byte buffer overflows for longer name+value, andsetenv(name, value, 0)on an existing variable returned -1 where POSIX returns 0.Change
Use
_putenv_s(copies its arguments), return POSIX results, include<string.h>/<stdlib.h>explicitly.Not included from nfc-tools#765: the
SCardDisconnect(..., SCARD_UNPOWER_CARD)change inacr122_pcsc.c. It is a behaviour change on real ACR122U hardware that I cannot test, so it stays a separate question.TDD
First commit adds a Windows-only test and makes the Windows job strict: it must be red. Second commit is the fix: it must be green.
🤖 Generated with Claude Code