チケット #40696

MSVCRT.DLL's _pgmptr variable is uninitialized by MinGW start-up code

登録: 2020-09-01 07:32 最終更新: 2021-04-13 02:19

報告者:
担当者:
チケットの種類:
状況:
完了
コンポーネント:
マイルストーン:
(未割り当て)
優先度:
5 - 中
重要度:
5 - 中
解決法:
修正済み
ファイル:
1
投票
点数: 0
No votes
0.0% (0/0)
0.0% (0/0)

詳細

According to Microsoft's GetModuleFileNameA() function documentation:

The global variable _pgmptr is automatically initialized to the full path of the executable file,
and can be used to retrieve the full path name of an executable file.
It appears that this global variable initialization occurs, only if the run-time start-up code calls Microsoft's __getmainargs() function, but that exhibits defective globbing of wild-card patterns, and MinGW has not used it, as a default start-up hook, since the release of mingwrt-3.21, in December 2014. Consequently, references to _pgmptr, in code linked against mingwrt-3.21 (and later), are likely to dereference a NULL pointer.

チケットの履歴 (10 件中 3 件表示)

2020-09-01 07:32 更新者: keith
  • 新しいチケット "MSVCRT.DLL's _pgmptr variable is unitialized by MinGW start-up code" が作成されました
2020-09-01 07:33 更新者: keith
  • 詳細が更新されました
2020-09-01 07:35 更新者: keith
  • 概要が更新されました
2020-09-02 04:31 更新者: keith
コメント

The following (trivial) program illustrates the issue:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #ifdef _CRT_GLOB
  4. int _CRT_glob = _CRT_GLOB;
  5. #endif
  6. int main()
  7. { printf( "_pgmptr = '%s'\n", _pgmptr );
  8. return 0;
  9. }
If I compile this, with default settings for _CRT_glob, link with current mingwrt, and run it (under MSYS) on a Win7, or WinXP VM, I see:
$ mingw32-gcc t-pgmptr.c -o pgmptr.exe
$ ./pgmptr.exe
_pgmptr = '(null)'
OTOH, if I compile it with -D_CRT_GLOB=1, or with -D_CRT_GLOB=0, either of which causes the mingwrt start-up code to call Microsoft's __getmainargs(), I see (as expected):
$ mingw32-gcc -D_CRT_GLOB=1 t-pgmptr.c -o pgmptr.exe
$ ./pgmptr.exe
_pgmptr = 'e:\sandbox\pgmptr.exe'

Curiously, I didn't notice the anomalous default behaviour previously, (testing on GNU/Linux, under Wine), because Wine's implementation of MSVCRT.DLL appears to initialize _pgmptr without __getmainargs() having been called.

2020-09-02 05:24 更新者: keith
  • 詳細が更新されました
2020-09-03 00:11 更新者: keith
  • 添付ファイル pgmptr-initialization.patch (File ID: 5664) が付加されました
2020-09-03 00:12 更新者: keith
  • 添付ファイル pgmptr-initialization.patch (File ID: 5664) が削除されました
2020-09-03 00:15 更新者: keith
  • 解決法なし から 修正済み に更新されました
コメント

The attached patch resolves the anomaly. I will include it in the next mingwrt release.

2021-04-13 02:19 更新者: keith
  • 状況オープン から 完了 に更新されました
コメント

This is fixed, in mingwrt-5.4.2.

添付ファイルリスト

編集

このチケットにコメントを追加するには、ログインが必要です » ログインする