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 custom date formats in i686 builds #3626

Merged
merged 2 commits into from
Jan 12, 2022

Conversation

dscho
Copy link
Member

@dscho dscho commented Jan 11, 2022

In i686 builds, this will crash with a segmentation fault:

git log --date='format:%Y-%m-%d %H:%M' --pretty='format:%cd'

(Note that if you try to reproduce this in a regular Git for Windows SDK, you will have to call make NDEBUG=1 to be able to reproduce the segmentation fault.)

The reason is that the strftime() function is imported with an incorrect calling convention. It is quite timely that Matthias Aßauer submitted a patch to address precisely this bug, and that contribution already made it into upstream's seen branch as the ma/windows-dynload-fix topic (and is slated to be fast-tracked into v2.35.0). This PR backports that topic, along with a fix-up for a patch that has not landed upstream yet so that the result still builds.

This fixes #3624

rimrul and others added 2 commits January 11, 2022 21:29
Christoph Reiter reported on the Git for Windows issue tracker[1], that
mingw_strftime() imports strftime() from ucrtbase.dll with the wrong
calling convention. It should be __cdecl instead of WINAPI, which we
always use in DECLARE_PROC_ADDR().

The MSYS2 project encountered cmake sefaults on x86 Windows caused by
the same issue in the cmake source. [2] There are no known git crashes
that where caused by this, yet, but we should try to prevent them.

We import two other non-WINAPI functions via DECLARE_PROC_ADDR(), too.

* NtSetSystemInformation() (NTAPI)
* GetUserNameExW()         (SEC_ENTRY)

NTAPI, SEC_ENTRY and WINAPI are all ususally defined as __stdcall,
but there are circumstances where they're defined differently.

Teach DECLARE_PROC_ADDR() about calling conventions and be explicit
about when we want to use which calling convention.

Import winnt.h for the definition of NTAPI and sspi.h for SEC_ENTRY
near their respective only users.

[1] git-for-windows#3560
[2] msys2/MINGW-packages#10152

Reported-By: Christoph Reiter <[email protected]>
Signed-off-by: Matthias Aßhauer <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
This is needed because the signature of `DECLARE_PROC_ADDR()` has
changed, as per `ma/windows-dynload-fix`.

Signed-off-by: Johannes Schindelin <[email protected]>
Copy link
Member

@rimrul rimrul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@@ -8,7 +8,7 @@ int win32_fsync_no_flush(int fd)

#define FLUSH_FLAGS_FILE_DATA_ONLY 1

DECLARE_PROC_ADDR(ntdll.dll, NTSTATUS, NtFlushBuffersFileEx,
DECLARE_PROC_ADDR(ntdll.dll, NTSTATUS, NTAPI, NtFlushBuffersFileEx,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing our NTAPI definition here comes from winternl.h here. I used winnt.h in t/helper/test-drop-caches.c we might want to make them use the same source at some point in the future, but this isn't urgent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing our NTAPI definition here comes from winternl.h here. I used winnt.h in t/helper/test-drop-caches.c we might want to make them use the same source at some point in the future, but this isn't urgent.

winternl.h #includes windef.h, which in turn #includes winnt.h.

So there is nothing we need to do here.

Besides, we can allow ourselves to trust the mingw-w64-headers to not #define parts as central as NTAPI in incompatible ways depending which header file you #include.

@dscho dscho merged commit b1e0460 into git-for-windows:main Jan 12, 2022
@dscho dscho deleted the windows-dynload-fix branch January 12, 2022 13:00
git-for-windows-ci pushed a commit that referenced this pull request Jan 12, 2022
Fix custom date formats in i686 builds
git-for-windows-ci pushed a commit that referenced this pull request Jan 12, 2022
Fix custom date formats in i686 builds
git-for-windows-ci pushed a commit that referenced this pull request Jan 12, 2022
Fix custom date formats in i686 builds
git-for-windows-ci pushed a commit that referenced this pull request Jan 12, 2022
Fix custom date formats in i686 builds
git-for-windows-ci pushed a commit that referenced this pull request Jan 12, 2022
Fix custom date formats in i686 builds
git-for-windows-ci pushed a commit that referenced this pull request Jan 13, 2022
Fix custom date formats in i686 builds
dscho added a commit that referenced this pull request Jan 13, 2022
Fix custom date formats in i686 builds
dscho added a commit that referenced this pull request Jan 13, 2022
Fix custom date formats in i686 builds
git-for-windows-ci pushed a commit that referenced this pull request Jan 14, 2022
Fix custom date formats in i686 builds
git-for-windows-ci pushed a commit that referenced this pull request Jan 14, 2022
Fix custom date formats in i686 builds
git-for-windows-ci pushed a commit that referenced this pull request Jan 14, 2022
Fix custom date formats in i686 builds
git-for-windows-ci pushed a commit that referenced this pull request Jan 14, 2022
Fix custom date formats in i686 builds
git-for-windows-ci pushed a commit that referenced this pull request Jan 14, 2022
Fix custom date formats in i686 builds
git-for-windows-ci pushed a commit that referenced this pull request Jan 14, 2022
Fix custom date formats in i686 builds
git-for-windows-ci pushed a commit that referenced this pull request Jan 14, 2022
Fix custom date formats in i686 builds
git-for-windows-ci pushed a commit that referenced this pull request Jan 14, 2022
Fix custom date formats in i686 builds
git-for-windows-ci pushed a commit that referenced this pull request Jan 14, 2022
Fix custom date formats in i686 builds
git-for-windows-ci pushed a commit that referenced this pull request Jan 15, 2022
Fix custom date formats in i686 builds
git-for-windows-ci pushed a commit that referenced this pull request Jan 15, 2022
Fix custom date formats in i686 builds
git-for-windows-ci pushed a commit that referenced this pull request Jan 15, 2022
Fix custom date formats in i686 builds
dscho added a commit that referenced this pull request Jan 16, 2022
Fix custom date formats in i686 builds
dscho added a commit that referenced this pull request Jan 20, 2022
Fix custom date formats in i686 builds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Git for Windows 2.26.1 and up crash on "git log" custom date format (--pretty='format:%cd')
2 participants