__mingw_fix_stat_path() also returns NULL if the given path is NULL.
In this case the _statXX function is still called so that it can set
errno = EINVAL or call invalid parameter handler.
---
 mingw-w64-crt/stdio/__mingw_fix_stat_path.c   | 2 ++
 mingw-w64-crt/stdio/__mingw_fix_wstat_path.c  | 2 ++
 mingw-w64-crt/stdio/msvcr110plus_stat32.c     | 2 ++
 mingw-w64-crt/stdio/msvcr110plus_stat64i32.c  | 2 ++
 mingw-w64-crt/stdio/msvcr110plus_wstat32.c    | 2 ++
 mingw-w64-crt/stdio/msvcr110plus_wstat64i32.c | 2 ++
 mingw-w64-crt/stdio/msvcr110pre_stat32.c      | 2 ++
 mingw-w64-crt/stdio/msvcr110pre_stat64i32.c   | 2 ++
 mingw-w64-crt/stdio/msvcr110pre_wstat32.c     | 2 ++
 mingw-w64-crt/stdio/msvcr110pre_wstat64i32.c  | 2 ++
 mingw-w64-crt/stdio/stat32i64.c               | 2 ++
 mingw-w64-crt/stdio/stat64.c                  | 2 ++
 mingw-w64-crt/stdio/wstat32i64.c              | 2 ++
 mingw-w64-crt/stdio/wstat64.c                 | 2 ++
 14 files changed, 28 insertions(+)

diff --git a/mingw-w64-crt/stdio/__mingw_fix_stat_path.c 
b/mingw-w64-crt/stdio/__mingw_fix_stat_path.c
index 6bc479805..7614491a9 100644
--- a/mingw-w64-crt/stdio/__mingw_fix_stat_path.c
+++ b/mingw-w64-crt/stdio/__mingw_fix_stat_path.c
@@ -55,6 +55,8 @@ char* __mingw_fix_stat_path (const char* _path)
     if (_path[len - 1] == '/' || _path[len - 1] == '\\')
       {
        p = (char*)malloc (len);
+       if (p == NULL)
+         return NULL; /* malloc has set errno. */
        memcpy (p, _path, len - 1);
        p[len - 1] = '\0';
       }
diff --git a/mingw-w64-crt/stdio/__mingw_fix_wstat_path.c 
b/mingw-w64-crt/stdio/__mingw_fix_wstat_path.c
index 89985b9b5..5826c4188 100644
--- a/mingw-w64-crt/stdio/__mingw_fix_wstat_path.c
+++ b/mingw-w64-crt/stdio/__mingw_fix_wstat_path.c
@@ -55,6 +55,8 @@ wchar_t* __mingw_fix_wstat_path (const wchar_t* _path)
     if (_path[len - 1] == L'/' || _path[len - 1] == L'\\')
       {
        p = (wchar_t*)malloc (len * sizeof(wchar_t));
+       if (p == NULL)
+         return NULL; /* malloc has set errno. */
        memcpy (p, _path, (len - 1) * sizeof(wchar_t));
        p[len - 1] = L'\0';
       }
diff --git a/mingw-w64-crt/stdio/msvcr110plus_stat32.c 
b/mingw-w64-crt/stdio/msvcr110plus_stat32.c
index 1ecf805e1..f4cb9567a 100644
--- a/mingw-w64-crt/stdio/msvcr110plus_stat32.c
+++ b/mingw-w64-crt/stdio/msvcr110plus_stat32.c
@@ -12,6 +12,8 @@ int __cdecl stat32(const char *_Filename, struct _stat32 
*_Stat);
 int __cdecl stat32(const char *_Filename, struct _stat32 *_Stat)
 {
   char *_path = __mingw_fix_stat_path(_Filename);
+  if (_path == NULL && _Filename != NULL)
+    return -1;
   int ret = _stat32(_path, _Stat);
   if (_path != _Filename)
     free(_path);
diff --git a/mingw-w64-crt/stdio/msvcr110plus_stat64i32.c 
b/mingw-w64-crt/stdio/msvcr110plus_stat64i32.c
index c524cf96d..7ccd23b34 100644
--- a/mingw-w64-crt/stdio/msvcr110plus_stat64i32.c
+++ b/mingw-w64-crt/stdio/msvcr110plus_stat64i32.c
@@ -12,6 +12,8 @@ int __cdecl stat64i32(const char *_Filename, struct 
_stat64i32 *_Stat);
 int __cdecl stat64i32(const char *_Filename, struct _stat64i32 *_Stat)
 {
   char *_path = __mingw_fix_stat_path(_Filename);
+  if (_path == NULL && _Filename != NULL)
+    return -1;
   int ret = _stat64i32(_path, _Stat);
   if (_path != _Filename)
     free(_path);
diff --git a/mingw-w64-crt/stdio/msvcr110plus_wstat32.c 
b/mingw-w64-crt/stdio/msvcr110plus_wstat32.c
index 54286398e..3c6576ae0 100644
--- a/mingw-w64-crt/stdio/msvcr110plus_wstat32.c
+++ b/mingw-w64-crt/stdio/msvcr110plus_wstat32.c
@@ -12,6 +12,8 @@ int __cdecl wstat32(const wchar_t *_Filename, struct _stat32 
*_Stat);
 int __cdecl wstat32(const wchar_t *_Filename, struct _stat32 *_Stat)
 {
   wchar_t *_path = __mingw_fix_wstat_path(_Filename);
+  if (_path == NULL && _Filename != NULL)
+    return -1;
   int ret = _wstat32(_path, _Stat);
   if (_path != _Filename)
     free(_path);
diff --git a/mingw-w64-crt/stdio/msvcr110plus_wstat64i32.c 
b/mingw-w64-crt/stdio/msvcr110plus_wstat64i32.c
index 1da8aca74..7fc681b2a 100644
--- a/mingw-w64-crt/stdio/msvcr110plus_wstat64i32.c
+++ b/mingw-w64-crt/stdio/msvcr110plus_wstat64i32.c
@@ -12,6 +12,8 @@ int __cdecl wstat64i32(const wchar_t *_Filename, struct 
_stat64i32 *_Stat);
 int __cdecl wstat64i32(const wchar_t *_Filename, struct _stat64i32 *_Stat)
 {
   wchar_t *_path = __mingw_fix_wstat_path(_Filename);
+  if (_path == NULL && _Filename != NULL)
+    return -1;
   int ret = _wstat64i32(_path, _Stat);
   if (_path != _Filename)
     free(_path);
diff --git a/mingw-w64-crt/stdio/msvcr110pre_stat32.c 
b/mingw-w64-crt/stdio/msvcr110pre_stat32.c
index 9577578bb..fe3cb20d6 100644
--- a/mingw-w64-crt/stdio/msvcr110pre_stat32.c
+++ b/mingw-w64-crt/stdio/msvcr110pre_stat32.c
@@ -20,6 +20,8 @@ int __cdecl stat32(const char *_Filename, struct _stat32 
*_Stat)
 {
   struct _stat32i64 st;
   char *_path = __mingw_fix_stat_path(_Filename);
+  if (_path == NULL && _Filename != NULL)
+    return -1;
   int ret = _stat32i64(_path, &st);
   if (_path != _Filename)
     free(_path);
diff --git a/mingw-w64-crt/stdio/msvcr110pre_stat64i32.c 
b/mingw-w64-crt/stdio/msvcr110pre_stat64i32.c
index fa43a31ed..d87a14f54 100644
--- a/mingw-w64-crt/stdio/msvcr110pre_stat64i32.c
+++ b/mingw-w64-crt/stdio/msvcr110pre_stat64i32.c
@@ -20,6 +20,8 @@ int __cdecl stat64i32(const char *_Filename, struct 
_stat64i32 *_Stat)
 {
   struct _stat64 st;
   char *_path = __mingw_fix_stat_path(_Filename);
+  if (_path == NULL && _Filename != NULL)
+    return -1;
   int ret = _stat64(_path, &st);
   if (_path != _Filename)
     free(_path);
diff --git a/mingw-w64-crt/stdio/msvcr110pre_wstat32.c 
b/mingw-w64-crt/stdio/msvcr110pre_wstat32.c
index 8ed720288..4fc02ee0f 100644
--- a/mingw-w64-crt/stdio/msvcr110pre_wstat32.c
+++ b/mingw-w64-crt/stdio/msvcr110pre_wstat32.c
@@ -20,6 +20,8 @@ int __cdecl wstat32(const wchar_t *_Filename, struct _stat32 
*_Stat)
 {
   struct _stat32i64 st;
   wchar_t *_path = __mingw_fix_wstat_path(_Filename);
+  if (_path == NULL && _Filename != NULL)
+    return -1;
   int ret = _wstat32i64(_path, &st);
   if (_path != _Filename)
     free(_path);
diff --git a/mingw-w64-crt/stdio/msvcr110pre_wstat64i32.c 
b/mingw-w64-crt/stdio/msvcr110pre_wstat64i32.c
index 553b938c4..21c10b58b 100644
--- a/mingw-w64-crt/stdio/msvcr110pre_wstat64i32.c
+++ b/mingw-w64-crt/stdio/msvcr110pre_wstat64i32.c
@@ -20,6 +20,8 @@ int __cdecl wstat64i32(const wchar_t *_Filename, struct 
_stat64i32 *_Stat)
 {
   struct _stat64 st;
   wchar_t *_path = __mingw_fix_wstat_path(_Filename);
+  if (_path == NULL && _Filename != NULL)
+    return -1;
   int ret = _wstat64(_path, &st);
   if (_path != _Filename)
     free(_path);
diff --git a/mingw-w64-crt/stdio/stat32i64.c b/mingw-w64-crt/stdio/stat32i64.c
index 38e8706b0..b8d154605 100644
--- a/mingw-w64-crt/stdio/stat32i64.c
+++ b/mingw-w64-crt/stdio/stat32i64.c
@@ -12,6 +12,8 @@ int __cdecl stat32i64(const char *_Filename, struct 
_stat32i64 *_Stat);
 int __cdecl stat32i64(const char *_Filename, struct _stat32i64 *_Stat)
 {
   char *_path = __mingw_fix_stat_path(_Filename);
+  if (_path == NULL && _Filename != NULL)
+    return -1;
   int ret = _stat32i64(_path, _Stat);
   if (_path != _Filename)
     free(_path);
diff --git a/mingw-w64-crt/stdio/stat64.c b/mingw-w64-crt/stdio/stat64.c
index 2dbd70865..687135f3e 100644
--- a/mingw-w64-crt/stdio/stat64.c
+++ b/mingw-w64-crt/stdio/stat64.c
@@ -11,6 +11,8 @@
 int __cdecl stat64(const char *_Filename, struct stat64 *_Stat)
 {
   char *_path = __mingw_fix_stat_path(_Filename);
+  if (_path == NULL && _Filename != NULL)
+    return -1;
   int ret = _stat64(_path, (struct _stat64 *)_Stat);
   if (_path != _Filename)
     free(_path);
diff --git a/mingw-w64-crt/stdio/wstat32i64.c b/mingw-w64-crt/stdio/wstat32i64.c
index b1e79c776..2dc34b8f9 100644
--- a/mingw-w64-crt/stdio/wstat32i64.c
+++ b/mingw-w64-crt/stdio/wstat32i64.c
@@ -12,6 +12,8 @@ int __cdecl wstat32i64(const wchar_t *_Filename, struct 
_stat32i64 *_Stat);
 int __cdecl wstat32i64(const wchar_t *_Filename, struct _stat32i64 *_Stat)
 {
   wchar_t *_path = __mingw_fix_wstat_path(_Filename);
+  if (_path == NULL && _Filename != NULL)
+    return -1;
   int ret = _wstat32i64(_path, _Stat);
   if (_path != _Filename)
     free(_path);
diff --git a/mingw-w64-crt/stdio/wstat64.c b/mingw-w64-crt/stdio/wstat64.c
index 5f2d92fc4..8cc58521a 100644
--- a/mingw-w64-crt/stdio/wstat64.c
+++ b/mingw-w64-crt/stdio/wstat64.c
@@ -11,6 +11,8 @@
 int __cdecl wstat64(const wchar_t *_Filename, struct stat64 *_Stat)
 {
   wchar_t *_path = __mingw_fix_wstat_path(_Filename);
+  if (_path == NULL && _Filename != NULL)
+    return -1;
   int ret = _wstat64(_path, (struct _stat64 *)_Stat);
   if (_path != _Filename)
     free(_path);
-- 
2.49.0



_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to