Fix Windows/MinGW build: missing err.h, uninitialized pointer in stdlib.c - #29
Open
doomfrawen wants to merge 1 commit into
Open
Fix Windows/MinGW build: missing err.h, uninitialized pointer in stdlib.c#29doomfrawen wants to merge 1 commit into
doomfrawen wants to merge 1 commit into
Conversation
…ib.c - src/nfc-utils.h/.c and src/windows.h include <err.h>, a BSD/glibc-only header not shipped by MinGW-w64, so the GNU-toolchain build (autoreconf + gcc, as opposed to the VS2019/clang-cl path this repo also supports) fails with 'err.h: No such file or directory'. windows.h doesn't call anything from it, so that include is simply dropped. nfc-utils.h's DBG/WARN/ERR macros do use warnx(), so on _WIN32 this adds a small static inline warnx() shim instead of the header, and drops the redundant second #include <err.h> in nfc-utils.c. - src/stdlib.c's setenv()/unsetenv() declare 'char *str[32]' (an array of 32 uninitialized pointers) and then do strcpy(*str, name) etc, which dereferences the first (uninitialized/garbage) pointer in that array and writes through it - undefined behavior, not just a compile-time type mismatch. Changed to 'char str[32]' (an actual 32-byte buffer) and dropped the erroneous dereferences.
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.
Building mfoc-hardnested for native Windows via the GNU toolchain path (
autoreconf -vis && ./configure && make, MSYS2 MinGW64) rather than the VS2019/clang-cl path hits two issues:1.
src/nfc-utils.h/.c,src/windows.h— include<err.h>, a BSD/glibc-only header not shipped by MinGW-w64, so the build fails witherr.h: No such file or directory.windows.hdoesn't call anything from it, so that include is simply dropped.nfc-utils.h's DBG/WARN/ERR macros do usewarnx(), so on_WIN32this adds a smallstatic inline warnx()shim instead of the header, and drops the now-redundant second#include <err.h>in nfc-utils.c.2.
src/stdlib.c—setenv()/unsetenv()declarechar *str[32](an array of 32 uninitialized pointers) and then dostrcpy(*str, name)etc, which dereferences the first garbage pointer in that array and writes through it. This is undefined behavior / a likely crash, not just a compile-time type mismatch (worth noting: this is a different, worse variant of a bug also present in upstream libnfc's contrib/win32/stdlib.c, which just declares the array without dereferencing it and so only fails to compile rather than corrupting memory). Changed tochar str[32](an actual 32-byte stack buffer) and removed the erroneous*dereferences.Both fixes are additive/platform-scoped and don't touch the existing VS/clang-cl build path or non-Windows behavior.