Even if _FORTIFY_SOURCE=2 is set, this patch allows for example:
struct { char header[4], payload[42], trailer[13]; } data;
n = read(fd, &data.payload, 42+13);
Same applies to fread() and memcpy(), memset(), ... .
The checks of other functions (str*(), *s*printf(), ...) are not affected.
From c853a56065835e055adb72f7288da8fa8eb53cf7 Mon Sep 17 00:00:00 2001
From: Christian Franke <[email protected]>
Date: Wed, 9 Oct 2019 21:57:50 +0200
Subject: [PATCH 2/2] headers: _FORTIFY_SOURCE: Limit level for functions which
work on raw memory.
Allow mem*() and *read() to use the memory up to the end of the whole variable
even if _FORITFY_SOURCE=2 is set.
---
mingw-w64-headers/crt/io.h | 2 +-
mingw-w64-headers/crt/stdio.h | 2 +-
mingw-w64-headers/crt/string.h | 10 +++++-----
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/mingw-w64-headers/crt/io.h b/mingw-w64-headers/crt/io.h
index a36d1f0a..b0f5d2b8 100644
--- a/mingw-w64-headers/crt/io.h
+++ b/mingw-w64-headers/crt/io.h
@@ -377,7 +377,7 @@ _CRTIMP int __cdecl __mingw_call__read(int, void *,
unsigned int) __MINGW_ASM_CR
__mingw_bos_extern_ovr
int _read(int __fh, void * __dst, unsigned int __n)
{
- __mingw_bos_ptr_chk_warn(__dst, __n, 1);
+ __mingw_bos_ptr_chk_warn(__dst, __n, 0);
return __mingw_call__read(__fh, __dst, __n);
}
diff --git a/mingw-w64-headers/crt/stdio.h b/mingw-w64-headers/crt/stdio.h
index 9446db60..4e201e91 100644
--- a/mingw-w64-headers/crt/stdio.h
+++ b/mingw-w64-headers/crt/stdio.h
@@ -809,7 +809,7 @@ char * fgets(char * __restrict__ __dst, int __n, FILE *
__restrict__ __f)
__mingw_bos_extern_ovr
size_t fread(void * __restrict__ __dst, size_t __sz, size_t __n, FILE *
__restrict__ __f)
{
- __mingw_bos_ptr_chk_warn(__dst, __sz * __n, 1);
+ __mingw_bos_ptr_chk_warn(__dst, __sz * __n, 0);
return __mingw_call_fread(__dst, __sz, __n, __f);
}
diff --git a/mingw-w64-headers/crt/string.h b/mingw-w64-headers/crt/string.h
index 1189ba23..49027c18 100644
--- a/mingw-w64-headers/crt/string.h
+++ b/mingw-w64-headers/crt/string.h
@@ -199,26 +199,26 @@ __mingw_bos_declare;
__mingw_bos_extern_ovr
void * memcpy(void * __restrict__ __dst, const void * __restrict__ __src,
size_t __n)
{
- return __builtin___memcpy_chk(__dst, __src, __n, __mingw_bos(__dst, 1));
+ return __builtin___memcpy_chk(__dst, __src, __n, __mingw_bos(__dst, 0));
}
__mingw_bos_extern_ovr
void * memset(void * __dst, int __val, size_t __n)
{
- return __builtin___memset_chk(__dst, __val, __n, __mingw_bos(__dst, 1));
+ return __builtin___memset_chk(__dst, __val, __n, __mingw_bos(__dst, 0));
}
__mingw_bos_extern_ovr
void * memmove(void * __dst, const void * __src, size_t __n)
{
- return __builtin___memmove_chk(__dst, __src, __n, __mingw_bos(__dst, 1));
+ return __builtin___memmove_chk(__dst, __src, __n, __mingw_bos(__dst, 0));
}
#ifdef _GNU_SOURCE
__mingw_bos_extern_ovr
void * mempcpy(void * __dst, const void * __src, size_t __n)
{
- return __builtin___mempcpy_chk(__dst, __src, __n, __mingw_bos(__dst, 1));
+ return __builtin___mempcpy_chk(__dst, __src, __n, __mingw_bos(__dst, 0));
}
#endif /* _GNU_SOURCE */
@@ -253,7 +253,7 @@ wchar_t * __cdecl __mingw_call_wcscat(wchar_t *
__restrict__, const wchar_t * __
__mingw_bos_extern_ovr
errno_t memcpy_s(void * __dst, size_t __os, const void * __src, size_t __n)
{
- __mingw_bos_ptr_chk_warn(__dst, __os, 1);
+ __mingw_bos_ptr_chk_warn(__dst, __os, 0);
return __mingw_call_memcpy_s(__dst, __os, __src, __n);
}
--
2.21.0
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public