* [PATCH 0/6] Fix/supress warnings with gcc 12
@ 2024-08-04 21:48 Jon Turney
2024-08-04 21:48 ` [PATCH 1/6] Cygwin: Suppress array-bounds warning from NtCurrentTeb() Jon Turney
` (5 more replies)
0 siblings, 6 replies; 18+ messages in thread
From: Jon Turney @ 2024-08-04 21:48 UTC (permalink / raw)
To: cygwin-patches; +Cc: Jon Turney
Fix/supress warnings seen with gcc 12.
Jon Turney (6):
Cygwin: Suppress array-bounds warning from NtCurrentTeb()
Cygwin: Fix warnings about narrowing conversions of NTSTATUS constants
Cygwin: Fix warning about address known to be non-NULL in
/proc/locales
Cygwin: Fix warning about narrowing conversions in tape options
Cygwin: Fix warnings about narrowing conversions of socket ioctls
Cygwin: Suppress false positive use-after-free warnings in
__set_lc_time_from_win()
winsup/cygwin/exceptions.cc | 2 +-
winsup/cygwin/fhandler/proc.cc | 3 +--
winsup/cygwin/fhandler/tape.cc | 4 ++--
winsup/cygwin/local_includes/mtinfo.h | 2 +-
winsup/cygwin/local_includes/ntdll.h | 2 +-
winsup/cygwin/local_includes/winlean.h | 3 +++
winsup/cygwin/net.cc | 2 +-
winsup/cygwin/nlsfuncs.cc | 10 ++++++++++
winsup/cygwin/pinfo.cc | 2 +-
winsup/cygwin/sigproc.cc | 2 +-
10 files changed, 22 insertions(+), 10 deletions(-)
--
2.45.1
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 1/6] Cygwin: Suppress array-bounds warning from NtCurrentTeb()
2024-08-04 21:48 [PATCH 0/6] Fix/supress warnings with gcc 12 Jon Turney
@ 2024-08-04 21:48 ` Jon Turney
2024-08-05 10:11 ` Corinna Vinschen
2024-08-04 21:48 ` [PATCH 2/6] Cygwin: Fix warnings about narrowing conversions of NTSTATUS constants Jon Turney
` (4 subsequent siblings)
5 siblings, 1 reply; 18+ messages in thread
From: Jon Turney @ 2024-08-04 21:48 UTC (permalink / raw)
To: cygwin-patches; +Cc: Jon Turney
This disables a warning seen with gcc 12 caused by intrinsics used by
the inline implementation of NtCurrentTeb() inside w32api headers.
> In function ‘long long unsigned int __readgsqword(unsigned int)’,
> inlined from ‘_TEB* NtCurrentTeb()’ at /usr/include/w32api/winnt.h:10020:86,
> [...]
> /usr/include/w32api/psdk_inc/intrin-impl.h:838:1: error: array subscript 0 is outside array bounds of ‘long long unsigned int [0]’ [-Werror=array-bounds]
See also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523#c6
---
winsup/cygwin/local_includes/winlean.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/winsup/cygwin/local_includes/winlean.h b/winsup/cygwin/local_includes/winlean.h
index 5bf1be262..62b651be6 100644
--- a/winsup/cygwin/local_includes/winlean.h
+++ b/winsup/cygwin/local_includes/winlean.h
@@ -53,7 +53,10 @@ details. */
#define __undef_CRITICAL
#endif
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
#include <windows.h>
+#pragma GCC diagnostic pop
#include <wincrypt.h>
#include <lmcons.h>
#include <ntdef.h>
--
2.45.1
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 2/6] Cygwin: Fix warnings about narrowing conversions of NTSTATUS constants
2024-08-04 21:48 [PATCH 0/6] Fix/supress warnings with gcc 12 Jon Turney
2024-08-04 21:48 ` [PATCH 1/6] Cygwin: Suppress array-bounds warning from NtCurrentTeb() Jon Turney
@ 2024-08-04 21:48 ` Jon Turney
2024-08-05 10:11 ` Corinna Vinschen
2024-08-04 21:48 ` [PATCH 3/6] Cygwin: Fix warning about address known to be non-NULL in /proc/locales Jon Turney
` (3 subsequent siblings)
5 siblings, 1 reply; 18+ messages in thread
From: Jon Turney @ 2024-08-04 21:48 UTC (permalink / raw)
To: cygwin-patches; +Cc: Jon Turney
Fix warnings with gcc 12 about narrowing conversions of NTSTATUS
constants when used as case labels, e.g:
> ../../../../src/winsup/cygwin/exceptions.cc: In static member function ‘static int exception::handle(EXCEPTION_RECORD*, void*, CONTEXT*, PDISPATCHER_CONTEXT)’:
> ../../../../src/winsup/cygwin/exceptions.cc:670:10: error: narrowing conversion of ‘-1073741682’ from ‘NTSTATUS’ {aka ‘int’} to ‘unsigned int’ [-Wnarrowing]
See also: c5bdf60ac46401a51a7e974333d9622966e22d67
---
winsup/cygwin/exceptions.cc | 2 +-
winsup/cygwin/local_includes/ntdll.h | 2 +-
winsup/cygwin/pinfo.cc | 2 +-
winsup/cygwin/sigproc.cc | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index 28d0431d5..74e5905d5 100644
--- a/winsup/cygwin/exceptions.cc
+++ b/winsup/cygwin/exceptions.cc
@@ -665,7 +665,7 @@ exception::handle (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT *in,
siginfo_t si = {};
si.si_code = SI_KERNEL;
/* Coerce win32 value to posix value. */
- switch (e->ExceptionCode)
+ switch ((NTSTATUS)e->ExceptionCode)
{
case STATUS_FLOAT_DIVIDE_BY_ZERO:
si.si_signo = SIGFPE;
diff --git a/winsup/cygwin/local_includes/ntdll.h b/winsup/cygwin/local_includes/ntdll.h
index 7737ae503..4497fe53f 100644
--- a/winsup/cygwin/local_includes/ntdll.h
+++ b/winsup/cygwin/local_includes/ntdll.h
@@ -23,7 +23,7 @@ extern GUID __cygwin_socket_guid;
/* Custom Cygwin-only status codes. */
#define STATUS_THREAD_SIGNALED ((NTSTATUS)0xe0000001)
#define STATUS_THREAD_CANCELED ((NTSTATUS)0xe0000002)
-#define STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION ((DWORD) 0xe0000269)
+#define STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION ((NTSTATUS) 0xe0000269)
/* Simplify checking for a transactional error code. */
#define NT_TRANSACTIONAL_ERROR(s) \
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc
index 7f1f41d79..d3c55d8d5 100644
--- a/winsup/cygwin/pinfo.cc
+++ b/winsup/cygwin/pinfo.cc
@@ -118,7 +118,7 @@ pinfo_init (char **envp, int envc)
DWORD
pinfo::status_exit (DWORD x)
{
- switch (x)
+ switch ((NTSTATUS)x)
{
case STATUS_DLL_NOT_FOUND:
{
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index 86e4e607a..82836fc3b 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -1082,7 +1082,7 @@ child_info::proc_retry (HANDLE h)
if (!exit_code)
return EXITCODE_OK;
sigproc_printf ("exit_code %y", exit_code);
- switch (exit_code)
+ switch ((NTSTATUS)exit_code)
{
case STILL_ACTIVE: /* shouldn't happen */
sigproc_printf ("STILL_ACTIVE? How'd we get here?");
--
2.45.1
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 3/6] Cygwin: Fix warning about address known to be non-NULL in /proc/locales
2024-08-04 21:48 [PATCH 0/6] Fix/supress warnings with gcc 12 Jon Turney
2024-08-04 21:48 ` [PATCH 1/6] Cygwin: Suppress array-bounds warning from NtCurrentTeb() Jon Turney
2024-08-04 21:48 ` [PATCH 2/6] Cygwin: Fix warnings about narrowing conversions of NTSTATUS constants Jon Turney
@ 2024-08-04 21:48 ` Jon Turney
2024-08-05 10:18 ` Corinna Vinschen
2024-08-04 21:48 ` [PATCH 4/6] Cygwin: Fix warning about narrowing conversions in tape options Jon Turney
` (2 subsequent siblings)
5 siblings, 1 reply; 18+ messages in thread
From: Jon Turney @ 2024-08-04 21:48 UTC (permalink / raw)
To: cygwin-patches; +Cc: Jon Turney
Fix a gcc 12 warning about an address known to be non-NULL in
format_proc_locale_proc().
> ../../../../src/winsup/cygwin/fhandler/proc.cc: In function ‘BOOL format_proc_locale_proc(LPWSTR, DWORD, LPARAM)’:
> ../../../../src/winsup/cygwin/fhandler/proc.cc:2156:11: error: the address of ‘iso15924’ will never be NULL [-Werror=address]
> 2156 | if (iso15924)
> | ^~~~~~~~
> ../../../../src/winsup/cygwin/fhandler/proc.cc:2133:11: note: ‘iso15924’ declared here
> 2133 | wchar_t iso15924[ENCODING_LEN + 1] = { 0 };
> | ^~~~~~~~
---
winsup/cygwin/fhandler/proc.cc | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/winsup/cygwin/fhandler/proc.cc b/winsup/cygwin/fhandler/proc.cc
index 8c7a4ab06..f1cd468fc 100644
--- a/winsup/cygwin/fhandler/proc.cc
+++ b/winsup/cygwin/fhandler/proc.cc
@@ -2193,8 +2193,7 @@ format_proc_locale_proc (LPWSTR win_locale, DWORD info, LPARAM param)
if (!(cp2 = wcschr (cp + 2, L'-')))
return TRUE;
/* Otherwise, store in iso15924 */
- if (iso15924)
- wcpcpy (wcpncpy (iso15924, cp, cp2 - cp), L";");
+ wcpcpy (wcpncpy (iso15924, cp, cp2 - cp), L";");
}
cp = wcsrchr (win_locale, L'-');
if (cp)
--
2.45.1
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 4/6] Cygwin: Fix warning about narrowing conversions in tape options
2024-08-04 21:48 [PATCH 0/6] Fix/supress warnings with gcc 12 Jon Turney
` (2 preceding siblings ...)
2024-08-04 21:48 ` [PATCH 3/6] Cygwin: Fix warning about address known to be non-NULL in /proc/locales Jon Turney
@ 2024-08-04 21:48 ` Jon Turney
2024-08-05 10:18 ` Corinna Vinschen
2024-08-04 21:48 ` [PATCH 5/6] Cygwin: Fix warnings about narrowing conversions of socket ioctls Jon Turney
2024-08-04 21:48 ` [PATCH 6/6] Cygwin: Suppress false positive use-after-free warnings in __set_lc_time_from_win() Jon Turney
5 siblings, 1 reply; 18+ messages in thread
From: Jon Turney @ 2024-08-04 21:48 UTC (permalink / raw)
To: cygwin-patches; +Cc: Jon Turney
Fix a gcc 12 warning about a narrowing conversion in case labels for
tape options.
> In file included from /wip/cygwin/src/winsup/cygwin/include/sys/mtio.h:14,
> from ../../../../src/winsup/cygwin/fhandler/tape.cc:13:
> ../../../../src/winsup/cygwin/fhandler/tape.cc: In member function ‘int mtinfo_drive::set_options(HANDLE, int32_t)’:
> ../../../../src/winsup/cygwin/fhandler/tape.cc:965:12: error: narrowing conversion of ‘4026531840’ from ‘unsigned int’ to ‘int’ [-Wnarrowing]
---
winsup/cygwin/fhandler/tape.cc | 4 ++--
winsup/cygwin/local_includes/mtinfo.h | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/winsup/cygwin/fhandler/tape.cc b/winsup/cygwin/fhandler/tape.cc
index 0e235f16c..732fd1bb7 100644
--- a/winsup/cygwin/fhandler/tape.cc
+++ b/winsup/cygwin/fhandler/tape.cc
@@ -894,9 +894,9 @@ mtinfo_drive::get_status (HANDLE mt, struct mtget *get)
}
int
-mtinfo_drive::set_options (HANDLE mt, int32_t options)
+mtinfo_drive::set_options (HANDLE mt, uint32_t options)
{
- int32_t what = (options & MT_ST_OPTIONS);
+ uint32_t what = (options & MT_ST_OPTIONS);
bool call_setparams = false;
bool set;
TAPE_SET_DRIVE_PARAMETERS sdp =
diff --git a/winsup/cygwin/local_includes/mtinfo.h b/winsup/cygwin/local_includes/mtinfo.h
index 03aabbfd0..46f8b1be9 100644
--- a/winsup/cygwin/local_includes/mtinfo.h
+++ b/winsup/cygwin/local_includes/mtinfo.h
@@ -101,7 +101,7 @@ class mtinfo_drive
int set_compression (HANDLE mt, int32_t count);
int set_blocksize (HANDLE mt, DWORD count);
int get_status (HANDLE mt, struct mtget *get);
- int set_options (HANDLE mt, int32_t options);
+ int set_options (HANDLE mt, uint32_t options);
int async_wait (HANDLE mt, DWORD *bytes_written);
public:
--
2.45.1
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 5/6] Cygwin: Fix warnings about narrowing conversions of socket ioctls
2024-08-04 21:48 [PATCH 0/6] Fix/supress warnings with gcc 12 Jon Turney
` (3 preceding siblings ...)
2024-08-04 21:48 ` [PATCH 4/6] Cygwin: Fix warning about narrowing conversions in tape options Jon Turney
@ 2024-08-04 21:48 ` Jon Turney
2024-08-05 10:22 ` Corinna Vinschen
2024-08-04 21:48 ` [PATCH 6/6] Cygwin: Suppress false positive use-after-free warnings in __set_lc_time_from_win() Jon Turney
5 siblings, 1 reply; 18+ messages in thread
From: Jon Turney @ 2024-08-04 21:48 UTC (permalink / raw)
To: cygwin-patches; +Cc: Jon Turney
Fix gcc 12 warnings about narrowing conversions of socket ioctl constants
when used as case labels, e.g:
> ../../../../src/winsup/cygwin/net.cc: In function ‘int get_ifconf(ifconf*, int)’:
> ../../../../src/winsup/cygwin/net.cc:1940:18: error: narrowing conversion of ‘2152756069’ from ‘long int’ to ‘int’ [-Wnarrowing]
---
winsup/cygwin/net.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index 08c584fe5..b76af2d19 100644
--- a/winsup/cygwin/net.cc
+++ b/winsup/cygwin/net.cc
@@ -1935,7 +1935,7 @@ get_ifconf (struct ifconf *ifc, int what)
{
++cnt;
strcpy (ifr->ifr_name, ifp->ifa_name);
- switch (what)
+ switch ((long int)what)
{
case SIOCGIFFLAGS:
ifr->ifr_flags = ifp->ifa_ifa.ifa_flags;
--
2.45.1
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 6/6] Cygwin: Suppress false positive use-after-free warnings in __set_lc_time_from_win()
2024-08-04 21:48 [PATCH 0/6] Fix/supress warnings with gcc 12 Jon Turney
` (4 preceding siblings ...)
2024-08-04 21:48 ` [PATCH 5/6] Cygwin: Fix warnings about narrowing conversions of socket ioctls Jon Turney
@ 2024-08-04 21:48 ` Jon Turney
2024-08-06 19:03 ` Jon Turney
5 siblings, 1 reply; 18+ messages in thread
From: Jon Turney @ 2024-08-04 21:48 UTC (permalink / raw)
To: cygwin-patches; +Cc: Jon Turney
Supress new use-after-free warnings about realloc(), seen with gcc 12, e.g.:
> In function ‘void rebase_locale_buf(const void*, const void*, const char*, const char*, const char*)’,
> inlined from ‘int __set_lc_time_from_win(const char*, const lc_time_T*, lc_time_T*, char**, wctomb_p, const char*)’ at ../../../../src/winsup/cygwin/nlsfuncs.cc:705:25:
> ../../../../src/winsup/cygwin/nlsfuncs.cc:338:24: error: pointer ‘new_lc_time_buf’ may be used after ‘void* realloc(void*, size_t)’ [-Werror=use-after-free]
> 338 | *ptrs += newbase - oldbase;
> | ~~~~~~~~^~~~~~~~~
> ../../../../src/winsup/cygwin/nlsfuncs.cc: In function ‘int __set_lc_time_from_win(const char*, const lc_time_T*, lc_time_T*, char**, wctomb_p, const char*)’:
> ../../../../src/winsup/cygwin/nlsfuncs.cc:699:44: note: call to ‘void* realloc(void*, size_t)’ here
> 699 | char *tmp = (char *) realloc (new_lc_time_buf, len);
We do some calculations using the pointer passed to realloc(), but do
not not dereference it, so this seems safe?
Because use-after-free is a new warning in gcc 12, we only disable it on
gcc 12 or later, to avoid warnings about unknown diagnostic options on
earlier gcc versions.
---
winsup/cygwin/nlsfuncs.cc | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/winsup/cygwin/nlsfuncs.cc b/winsup/cygwin/nlsfuncs.cc
index b32fecc8e..cf0e96d2d 100644
--- a/winsup/cygwin/nlsfuncs.cc
+++ b/winsup/cygwin/nlsfuncs.cc
@@ -324,6 +324,10 @@ locale_cmp (const void *a, const void *b)
structures consist entirely of pointers so they are practically pointer
arrays. What we do here is just treat the lc_foo pointers as char ** and
rebase all char * pointers within, up to the given size of the structure. */
+#pragma GCC diagnostic push
+#if __GNUC__ >= 12
+#pragma GCC diagnostic ignored "-Wuse-after-free"
+#endif
static void
rebase_locale_buf (const void *ptrv, const void *ptrvend, const char *newbase,
const char *oldbase, const char *oldend)
@@ -333,6 +337,7 @@ rebase_locale_buf (const void *ptrv, const void *ptrvend, const char *newbase,
if (*ptrs >= oldbase && *ptrs < oldend)
*ptrs += newbase - oldbase;
}
+#pragma GCC diagnostic pop
static wchar_t *
__getlocaleinfo (wchar_t *loc, LCTYPE type, char **ptr, size_t size)
@@ -699,7 +704,12 @@ __set_lc_time_from_win (const char *name,
if (tmp != new_lc_time_buf)
rebase_locale_buf (_time_locale, _time_locale + 1, tmp,
new_lc_time_buf, lc_time_ptr);
+#pragma GCC diagnostic push
+#if __GNUC__ >= 12
+#pragma GCC diagnostic ignored "-Wuse-after-free"
+#endif
lc_time_ptr = tmp + (lc_time_ptr - new_lc_time_buf);
+#pragma GCC diagnostic pop
new_lc_time_buf = tmp;
lc_time_end = new_lc_time_buf + len;
}
--
2.45.1
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 1/6] Cygwin: Suppress array-bounds warning from NtCurrentTeb()
2024-08-04 21:48 ` [PATCH 1/6] Cygwin: Suppress array-bounds warning from NtCurrentTeb() Jon Turney
@ 2024-08-05 10:11 ` Corinna Vinschen
0 siblings, 0 replies; 18+ messages in thread
From: Corinna Vinschen @ 2024-08-05 10:11 UTC (permalink / raw)
To: cygwin-patches
On Aug 4 22:48, Jon Turney wrote:
> This disables a warning seen with gcc 12 caused by intrinsics used by
> the inline implementation of NtCurrentTeb() inside w32api headers.
>
> > In function ‘long long unsigned int __readgsqword(unsigned int)’,
> > inlined from ‘_TEB* NtCurrentTeb()’ at /usr/include/w32api/winnt.h:10020:86,
> > [...]
> > /usr/include/w32api/psdk_inc/intrin-impl.h:838:1: error: array subscript 0 is outside array bounds of ‘long long unsigned int [0]’ [-Werror=array-bounds]
>
> See also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523#c6
> ---
> winsup/cygwin/local_includes/winlean.h | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/winsup/cygwin/local_includes/winlean.h b/winsup/cygwin/local_includes/winlean.h
> index 5bf1be262..62b651be6 100644
> --- a/winsup/cygwin/local_includes/winlean.h
> +++ b/winsup/cygwin/local_includes/winlean.h
> @@ -53,7 +53,10 @@ details. */
> #define __undef_CRITICAL
> #endif
>
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Warray-bounds"
> #include <windows.h>
> +#pragma GCC diagnostic pop
> #include <wincrypt.h>
> #include <lmcons.h>
> #include <ntdef.h>
> --
> 2.45.1
Looks like every other way to workaround this is worse. Please push.
Thanks,
Corinna
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 2/6] Cygwin: Fix warnings about narrowing conversions of NTSTATUS constants
2024-08-04 21:48 ` [PATCH 2/6] Cygwin: Fix warnings about narrowing conversions of NTSTATUS constants Jon Turney
@ 2024-08-05 10:11 ` Corinna Vinschen
0 siblings, 0 replies; 18+ messages in thread
From: Corinna Vinschen @ 2024-08-05 10:11 UTC (permalink / raw)
To: cygwin-patches
On Aug 4 22:48, Jon Turney wrote:
> Fix warnings with gcc 12 about narrowing conversions of NTSTATUS
> constants when used as case labels, e.g:
>
> > ../../../../src/winsup/cygwin/exceptions.cc: In static member function ‘static int exception::handle(EXCEPTION_RECORD*, void*, CONTEXT*, PDISPATCHER_CONTEXT)’:
> > ../../../../src/winsup/cygwin/exceptions.cc:670:10: error: narrowing conversion of ‘-1073741682’ from ‘NTSTATUS’ {aka ‘int’} to ‘unsigned int’ [-Wnarrowing]
>
> See also: c5bdf60ac46401a51a7e974333d9622966e22d67
> ---
> winsup/cygwin/exceptions.cc | 2 +-
> winsup/cygwin/local_includes/ntdll.h | 2 +-
> winsup/cygwin/pinfo.cc | 2 +-
> winsup/cygwin/sigproc.cc | 2 +-
> 4 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
> index 28d0431d5..74e5905d5 100644
> --- a/winsup/cygwin/exceptions.cc
> +++ b/winsup/cygwin/exceptions.cc
> @@ -665,7 +665,7 @@ exception::handle (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT *in,
> siginfo_t si = {};
> si.si_code = SI_KERNEL;
> /* Coerce win32 value to posix value. */
> - switch (e->ExceptionCode)
> + switch ((NTSTATUS)e->ExceptionCode)
I'd prefer a space after the closing parenthesis of the cast, but
we didn't enforce this in the past, so, please push.
Thanks,
Corinna
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 3/6] Cygwin: Fix warning about address known to be non-NULL in /proc/locales
2024-08-04 21:48 ` [PATCH 3/6] Cygwin: Fix warning about address known to be non-NULL in /proc/locales Jon Turney
@ 2024-08-05 10:18 ` Corinna Vinschen
0 siblings, 0 replies; 18+ messages in thread
From: Corinna Vinschen @ 2024-08-05 10:18 UTC (permalink / raw)
To: cygwin-patches
On Aug 4 22:48, Jon Turney wrote:
> Fix a gcc 12 warning about an address known to be non-NULL in
> format_proc_locale_proc().
>
> > ../../../../src/winsup/cygwin/fhandler/proc.cc: In function ‘BOOL format_proc_locale_proc(LPWSTR, DWORD, LPARAM)’:
> > ../../../../src/winsup/cygwin/fhandler/proc.cc:2156:11: error: the address of ‘iso15924’ will never be NULL [-Werror=address]
> > 2156 | if (iso15924)
> > | ^~~~~~~~
> > ../../../../src/winsup/cygwin/fhandler/proc.cc:2133:11: note: ‘iso15924’ declared here
> > 2133 | wchar_t iso15924[ENCODING_LEN + 1] = { 0 };
> > | ^~~~~~~~
> ---
> winsup/cygwin/fhandler/proc.cc | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/winsup/cygwin/fhandler/proc.cc b/winsup/cygwin/fhandler/proc.cc
> index 8c7a4ab06..f1cd468fc 100644
> --- a/winsup/cygwin/fhandler/proc.cc
> +++ b/winsup/cygwin/fhandler/proc.cc
> @@ -2193,8 +2193,7 @@ format_proc_locale_proc (LPWSTR win_locale, DWORD info, LPARAM param)
> if (!(cp2 = wcschr (cp + 2, L'-')))
> return TRUE;
> /* Otherwise, store in iso15924 */
> - if (iso15924)
> - wcpcpy (wcpncpy (iso15924, cp, cp2 - cp), L";");
> + wcpcpy (wcpncpy (iso15924, cp, cp2 - cp), L";");
> }
> cp = wcsrchr (win_locale, L'-');
> if (cp)
> --
> 2.45.1
I think iso15924 was supposed to be a pointer at first and after
converting it to an array I just forgot to take out the check.
Can you please add
Fixes: c42b98bdc665f ("Cygwin: introduce /proc/codesets and /proc/locales")
Oh and, while I'm at it, please add your Signed-off-by to all your
patches.
Thanks,
Corinna
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 4/6] Cygwin: Fix warning about narrowing conversions in tape options
2024-08-04 21:48 ` [PATCH 4/6] Cygwin: Fix warning about narrowing conversions in tape options Jon Turney
@ 2024-08-05 10:18 ` Corinna Vinschen
0 siblings, 0 replies; 18+ messages in thread
From: Corinna Vinschen @ 2024-08-05 10:18 UTC (permalink / raw)
To: cygwin-patches
On Aug 4 22:48, Jon Turney wrote:
> Fix a gcc 12 warning about a narrowing conversion in case labels for
> tape options.
>
> > In file included from /wip/cygwin/src/winsup/cygwin/include/sys/mtio.h:14,
> > from ../../../../src/winsup/cygwin/fhandler/tape.cc:13:
> > ../../../../src/winsup/cygwin/fhandler/tape.cc: In member function ‘int mtinfo_drive::set_options(HANDLE, int32_t)’:
> > ../../../../src/winsup/cygwin/fhandler/tape.cc:965:12: error: narrowing conversion of ‘4026531840’ from ‘unsigned int’ to ‘int’ [-Wnarrowing]
> ---
> winsup/cygwin/fhandler/tape.cc | 4 ++--
> winsup/cygwin/local_includes/mtinfo.h | 2 +-
> 2 files changed, 3 insertions(+), 3 deletions(-)
With Signed-off-by, LGTM.
Thanks,
Corinna
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 5/6] Cygwin: Fix warnings about narrowing conversions of socket ioctls
2024-08-04 21:48 ` [PATCH 5/6] Cygwin: Fix warnings about narrowing conversions of socket ioctls Jon Turney
@ 2024-08-05 10:22 ` Corinna Vinschen
2024-08-06 18:58 ` Jon Turney
0 siblings, 1 reply; 18+ messages in thread
From: Corinna Vinschen @ 2024-08-05 10:22 UTC (permalink / raw)
To: cygwin-patches
On Aug 4 22:48, Jon Turney wrote:
> Fix gcc 12 warnings about narrowing conversions of socket ioctl constants
> when used as case labels, e.g:
>
> > ../../../../src/winsup/cygwin/net.cc: In function ‘int get_ifconf(ifconf*, int)’:
> > ../../../../src/winsup/cygwin/net.cc:1940:18: error: narrowing conversion of ‘2152756069’ from ‘long int’ to ‘int’ [-Wnarrowing]
> ---
> winsup/cygwin/net.cc | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
> index 08c584fe5..b76af2d19 100644
> --- a/winsup/cygwin/net.cc
> +++ b/winsup/cygwin/net.cc
> @@ -1935,7 +1935,7 @@ get_ifconf (struct ifconf *ifc, int what)
> {
> ++cnt;
> strcpy (ifr->ifr_name, ifp->ifa_name);
> - switch (what)
> + switch ((long int)what)
> {
> case SIOCGIFFLAGS:
> ifr->ifr_flags = ifp->ifa_ifa.ifa_flags;
> --
> 2.45.1
The only caller, fhandler_socket::ioctl, passes an unsigned int
value to get_ifconf. Given how the value is defined, it would be
more straightforward to convert get_ifconf to
get_ifconf (struct ifconf *ifc, unsigned int what);
wouldn't it?
Thanks,
Corinna
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 5/6] Cygwin: Fix warnings about narrowing conversions of socket ioctls
2024-08-05 10:22 ` Corinna Vinschen
@ 2024-08-06 18:58 ` Jon Turney
2024-08-07 14:06 ` Corinna Vinschen
0 siblings, 1 reply; 18+ messages in thread
From: Jon Turney @ 2024-08-06 18:58 UTC (permalink / raw)
To: Corinna Vinschen; +Cc: cygwin-patches
[-- Attachment #1: Type: text/plain, Size: 1545 bytes --]
On 05/08/2024 11:22, Corinna Vinschen wrote:
> On Aug 4 22:48, Jon Turney wrote:
>> Fix gcc 12 warnings about narrowing conversions of socket ioctl constants
>> when used as case labels, e.g:
>>
>>> ../../../../src/winsup/cygwin/net.cc: In function ‘int get_ifconf(ifconf*, int)’:
>>> ../../../../src/winsup/cygwin/net.cc:1940:18: error: narrowing conversion of ‘2152756069’ from ‘long int’ to ‘int’ [-Wnarrowing]
>> ---
>> winsup/cygwin/net.cc | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
>> index 08c584fe5..b76af2d19 100644
>> --- a/winsup/cygwin/net.cc
>> +++ b/winsup/cygwin/net.cc
>> @@ -1935,7 +1935,7 @@ get_ifconf (struct ifconf *ifc, int what)
>> {
>> ++cnt;
>> strcpy (ifr->ifr_name, ifp->ifa_name);
>> - switch (what)
>> + switch ((long int)what)
>> {
>> case SIOCGIFFLAGS:
>> ifr->ifr_flags = ifp->ifa_ifa.ifa_flags;
>> --
>> 2.45.1
>
> The only caller, fhandler_socket::ioctl, passes an unsigned int
> value to get_ifconf. Given how the value is defined, it would be
> more straightforward to convert get_ifconf to
>
> get_ifconf (struct ifconf *ifc, unsigned int what);
>
> wouldn't it?
Yeah, I'm not sure why I didn't do that. I think I got confused about
where this is used from.
(These constants are long int though, for whatever reason, so it's not
immediately obvious that they all can be converted to unsigned int
without loss, but it seems they can)
Revised patch attached.
[-- Attachment #2: 0001-Cygwin-Fix-warnings-about-narrowing-conversions-of-s.patch --]
[-- Type: text/plain, Size: 1703 bytes --]
From df8b1ffd6ef7a9808a2d5eebf4b6416d45841e36 Mon Sep 17 00:00:00 2001
From: Jon Turney <jon.turney@dronecode.org.uk>
Date: Sun, 4 Aug 2024 17:02:00 +0100
Subject: [PATCH] Cygwin: Fix warnings about narrowing conversions of socket
ioctls
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Fix gcc 12 warnings about narrowing conversions of socket ioctl constants
when used as case labels, e.g:
> ../../../../src/winsup/cygwin/net.cc: In function ‘int get_ifconf(ifconf*, int)’:
> ../../../../src/winsup/cygwin/net.cc:1940:18: error: narrowing conversion of ‘2152756069’ from ‘long int’ to ‘int’ [-Wnarrowing]
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
---
winsup/cygwin/fhandler/socket.cc | 2 +-
winsup/cygwin/net.cc | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/winsup/cygwin/fhandler/socket.cc b/winsup/cygwin/fhandler/socket.cc
index f7c5ff629..c0cef7d3e 100644
--- a/winsup/cygwin/fhandler/socket.cc
+++ b/winsup/cygwin/fhandler/socket.cc
@@ -86,7 +86,7 @@ struct __old_ifreq {
int
fhandler_socket::ioctl (unsigned int cmd, void *p)
{
- extern int get_ifconf (struct ifconf *ifc, int what); /* net.cc */
+ extern int get_ifconf (struct ifconf *ifc, unsigned int what); /* net.cc */
int res;
struct ifconf ifc, *ifcp;
struct ifreq *ifrp;
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index 08c584fe5..737e494f8 100644
--- a/winsup/cygwin/net.cc
+++ b/winsup/cygwin/net.cc
@@ -1912,7 +1912,7 @@ freeifaddrs (struct ifaddrs *ifp)
}
int
-get_ifconf (struct ifconf *ifc, int what)
+get_ifconf (struct ifconf *ifc, unsigned int what)
{
__try
{
--
2.45.1
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 6/6] Cygwin: Suppress false positive use-after-free warnings in __set_lc_time_from_win()
2024-08-04 21:48 ` [PATCH 6/6] Cygwin: Suppress false positive use-after-free warnings in __set_lc_time_from_win() Jon Turney
@ 2024-08-06 19:03 ` Jon Turney
2024-08-07 14:18 ` Corinna Vinschen
0 siblings, 1 reply; 18+ messages in thread
From: Jon Turney @ 2024-08-06 19:03 UTC (permalink / raw)
Cc: cygwin-patches
[-- Attachment #1: Type: text/plain, Size: 1426 bytes --]
On 04/08/2024 22:48, Jon Turney wrote:
> Supress new use-after-free warnings about realloc(), seen with gcc 12, e.g.:
>
>> In function ‘void rebase_locale_buf(const void*, const void*, const char*, const char*, const char*)’,
>> inlined from ‘int __set_lc_time_from_win(const char*, const lc_time_T*, lc_time_T*, char**, wctomb_p, const char*)’ at ../../../../src/winsup/cygwin/nlsfuncs.cc:705:25:
>> ../../../../src/winsup/cygwin/nlsfuncs.cc:338:24: error: pointer ‘new_lc_time_buf’ may be used after ‘void* realloc(void*, size_t)’ [-Werror=use-after-free]
>> 338 | *ptrs += newbase - oldbase;
>> | ~~~~~~~~^~~~~~~~~
>> ../../../../src/winsup/cygwin/nlsfuncs.cc: In function ‘int __set_lc_time_from_win(const char*, const lc_time_T*, lc_time_T*, char**, wctomb_p, const char*)’:
>> ../../../../src/winsup/cygwin/nlsfuncs.cc:699:44: note: call to ‘void* realloc(void*, size_t)’ here
>> 699 | char *tmp = (char *) realloc (new_lc_time_buf, len);
>
> We do some calculations using the pointer passed to realloc(), but do
> not not dereference it, so this seems safe?
Since this is less than ideal, here's the version where we explicitly
malloc() the new buffer, adjust things, then free() the old buffer.
This is all quite hairy, though, and I have no idea how to begin to test
this, so if you have some pointers to share, that would be good.
[-- Attachment #2: 0001-Cygwin-Avoid-use-after-free-warnings-in-__set_lc_tim.patch --]
[-- Type: text/plain, Size: 6844 bytes --]
From 8f90b214c67db5fec42a7e9b51d5c2a8ec4d1510 Mon Sep 17 00:00:00 2001
From: Jon Turney <jon.turney@dronecode.org.uk>
Date: Sun, 4 Aug 2024 17:15:50 +0100
Subject: [PATCH] Cygwin: Avoid use-after-free warnings in
__set_lc_time_from_win() etc.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Rewrite to avoid new use-after-free warnings about realloc(), seen with
gcc 12, e.g.:
> In function ‘void rebase_locale_buf(const void*, const void*, const char*, const char*, const char*)’,
> inlined from ‘int __set_lc_time_from_win(const char*, const lc_time_T*, lc_time_T*, char**, wctomb_p, const char*)’ at ../../../../src/winsup/cygwin/nlsfuncs.cc:705:25:
> ../../../../src/winsup/cygwin/nlsfuncs.cc:338:24: error: pointer ‘new_lc_time_buf’ may be used after ‘void* realloc(void*, size_t)’ [-Werror=use-after-free]
> 338 | *ptrs += newbase - oldbase;
> | ~~~~~~~~^~~~~~~~~
> ../../../../src/winsup/cygwin/nlsfuncs.cc: In function ‘int __set_lc_time_from_win(const char*, const lc_time_T*, lc_time_T*, char**, wctomb_p, const char*)’:
> ../../../../src/winsup/cygwin/nlsfuncs.cc:699:44: note: call to ‘void* realloc(void*, size_t)’ here
> 699 | char *tmp = (char *) realloc (new_lc_time_buf, len);
Technically, it's UB to later refer to the realloced pointer (even just
for offset computations, without deferencing it), so switch to using
malloc() to create the resized copy.
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
---
winsup/cygwin/nlsfuncs.cc | 95 +++++++++++++++++----------------------
1 file changed, 41 insertions(+), 54 deletions(-)
diff --git a/winsup/cygwin/nlsfuncs.cc b/winsup/cygwin/nlsfuncs.cc
index b32fecc8e..1b33cb79f 100644
--- a/winsup/cygwin/nlsfuncs.cc
+++ b/winsup/cygwin/nlsfuncs.cc
@@ -319,8 +319,7 @@ locale_cmp (const void *a, const void *b)
return strcmp (*la, *lb);
}
-/* Helper function to workaround reallocs which move blocks even if they shrink.
- Cygwin's realloc is not doing this, but tcsh's, for instance. All lc_foo
+/* Helper function to adjust pointers inside a lc_foo buffer. All lc_foo
structures consist entirely of pointers so they are practically pointer
arrays. What we do here is just treat the lc_foo pointers as char ** and
rebase all char * pointers within, up to the given size of the structure. */
@@ -334,6 +333,28 @@ rebase_locale_buf (const void *ptrv, const void *ptrvend, const char *newbase,
*ptrs += newbase - oldbase;
}
+/* Helper function to shrink a lc_foo buffer, adjusting pointers */
+static int
+shrink_local_buf (const void *ptrv, const void *ptrvend,
+ char *oldbase, const char *oldend,
+ char **result)
+{
+ size_t minsize = oldend - oldbase;
+ char *tmp = (char *) malloc (minsize);
+ if (!tmp)
+ {
+ free (oldbase);
+ return -1;
+ }
+
+ memcpy (tmp, oldbase, minsize);
+ rebase_locale_buf (ptrv, ptrvend, tmp, oldbase, oldend);
+ free (oldbase);
+
+ *result = tmp;
+ return 1;
+}
+
static wchar_t *
__getlocaleinfo (wchar_t *loc, LCTYPE type, char **ptr, size_t size)
{
@@ -687,19 +708,20 @@ __set_lc_time_from_win (const char *name,
len += (wcslen (era->era_t_fmt) + 1) * sizeof (wchar_t);
len += (wcslen (era->alt_digits) + 1) * sizeof (wchar_t);
- /* Make sure data fits into the buffer */
+ /* If necessary, grow the buffer to ensure data fits into it */
if (lc_time_ptr + len > lc_time_end)
{
len = lc_time_ptr + len - new_lc_time_buf;
- char *tmp = (char *) realloc (new_lc_time_buf, len);
+ char *tmp = (char *) malloc (len);
if (!tmp)
era = NULL;
else
{
- if (tmp != new_lc_time_buf)
- rebase_locale_buf (_time_locale, _time_locale + 1, tmp,
- new_lc_time_buf, lc_time_ptr);
+ memcpy (tmp, new_lc_time_buf, MAX_TIME_BUFFER_SIZE);
+ rebase_locale_buf (_time_locale, _time_locale + 1, tmp,
+ new_lc_time_buf, lc_time_ptr);
lc_time_ptr = tmp + (lc_time_ptr - new_lc_time_buf);
+ free(new_lc_time_buf);
new_lc_time_buf = tmp;
lc_time_end = new_lc_time_buf + len;
}
@@ -752,17 +774,9 @@ __set_lc_time_from_win (const char *name,
}
}
- char *tmp = (char *) realloc (new_lc_time_buf, lc_time_ptr - new_lc_time_buf);
- if (!tmp)
- {
- free (new_lc_time_buf);
- return -1;
- }
- if (tmp != new_lc_time_buf)
- rebase_locale_buf (_time_locale, _time_locale + 1, tmp,
- new_lc_time_buf, lc_time_ptr);
- *lc_time_buf = tmp;
- return 1;
+ return shrink_local_buf(_time_locale, _time_locale + 1,
+ new_lc_time_buf, lc_time_ptr,
+ lc_time_buf);
}
/* Called from newlib's setlocale() via __ctype_load_locale() if category
@@ -824,18 +838,9 @@ __set_lc_ctype_from_win (const char *name,
}
}
- char *tmp = (char *) realloc (new_lc_ctype_buf,
- lc_ctype_ptr - new_lc_ctype_buf);
- if (!tmp)
- {
- free (new_lc_ctype_buf);
- return -1;
- }
- if (tmp != new_lc_ctype_buf)
- rebase_locale_buf (_ctype_locale, _ctype_locale + 1, tmp,
- new_lc_ctype_buf, lc_ctype_ptr);
- *lc_ctype_buf = tmp;
- return 1;
+ return shrink_local_buf(_ctype_locale, _ctype_locale + 1,
+ new_lc_ctype_buf, lc_ctype_ptr,
+ lc_ctype_buf);
}
/* Called from newlib's setlocale() via __numeric_load_locale() if category
@@ -900,18 +905,9 @@ __set_lc_numeric_from_win (const char *name,
_numeric_locale->codeset = lc_numeric_ptr;
lc_numeric_ptr = stpcpy (lc_numeric_ptr, charset) + 1;
- char *tmp = (char *) realloc (new_lc_numeric_buf,
- lc_numeric_ptr - new_lc_numeric_buf);
- if (!tmp)
- {
- free (new_lc_numeric_buf);
- return -1;
- }
- if (tmp != new_lc_numeric_buf)
- rebase_locale_buf (_numeric_locale, _numeric_locale + 1, tmp,
- new_lc_numeric_buf, lc_numeric_ptr);
- *lc_numeric_buf = tmp;
- return 1;
+ return shrink_local_buf(_numeric_locale, _numeric_locale + 1,
+ new_lc_numeric_buf, lc_numeric_ptr,
+ lc_numeric_buf);
}
/* Called from newlib's setlocale() via __monetary_load_locale() if category
@@ -1039,18 +1035,9 @@ __set_lc_monetary_from_win (const char *name,
_monetary_locale->codeset = lc_monetary_ptr;
lc_monetary_ptr = stpcpy (lc_monetary_ptr, charset) + 1;
- char *tmp = (char *) realloc (new_lc_monetary_buf,
- lc_monetary_ptr - new_lc_monetary_buf);
- if (!tmp)
- {
- free (new_lc_monetary_buf);
- return -1;
- }
- if (tmp != new_lc_monetary_buf)
- rebase_locale_buf (_monetary_locale, _monetary_locale + 1, tmp,
- new_lc_monetary_buf, lc_monetary_ptr);
- *lc_monetary_buf = tmp;
- return 1;
+ return shrink_local_buf(_monetary_locale, _monetary_locale + 1,
+ new_lc_monetary_buf, lc_monetary_ptr,
+ lc_monetary_buf);
}
extern "C" int
--
2.45.1
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 5/6] Cygwin: Fix warnings about narrowing conversions of socket ioctls
2024-08-06 18:58 ` Jon Turney
@ 2024-08-07 14:06 ` Corinna Vinschen
2024-08-11 18:31 ` Brian Inglis
0 siblings, 1 reply; 18+ messages in thread
From: Corinna Vinschen @ 2024-08-07 14:06 UTC (permalink / raw)
To: cygwin-patches
On Aug 6 19:58, Jon Turney wrote:
> On 05/08/2024 11:22, Corinna Vinschen wrote:
> > On Aug 4 22:48, Jon Turney wrote:
> > > Fix gcc 12 warnings about narrowing conversions of socket ioctl constants
> > > when used as case labels, e.g:
> > > [...]
> > The only caller, fhandler_socket::ioctl, passes an unsigned int
> > value to get_ifconf. Given how the value is defined, it would be
> > more straightforward to convert get_ifconf to
> >
> > get_ifconf (struct ifconf *ifc, unsigned int what);
> >
> > wouldn't it?
>
> Yeah, I'm not sure why I didn't do that. I think I got confused about where
> this is used from.
>
> (These constants are long int though, for whatever reason, so it's not
This is really old stuff. The _IO definitions have been taken from BSD
in some year with a 19 in front and never changed again. The fact that
the sizeof() gets cast to long is probably a remnant from the past when
the stuff was supposed to be used on 16 bit machines, but the value was
supposed to be 32 bit.
Given that the values are not supposed to be ever bigger than 32 bit,
we should fix the definitions of _IOR/_IOW, dropping the (long) cast.
Compare with current FreeBSD, which does not cast at all.
I did a quick check that dropping the cast does not change the value
of any of the dependent definitions in Cygwin headers. That shouldn't
happen anyway, given sizeof() returns a size_t, i. e. 64 bit unsigned.
> immediately obvious that they all can be converted to unsigned int without
> loss, but it seems they can)
>
> Revised patch attached.
LGTM. I will additionally push a patch dropping the useless casts.
Thanks,
Corinna
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 6/6] Cygwin: Suppress false positive use-after-free warnings in __set_lc_time_from_win()
2024-08-06 19:03 ` Jon Turney
@ 2024-08-07 14:18 ` Corinna Vinschen
0 siblings, 0 replies; 18+ messages in thread
From: Corinna Vinschen @ 2024-08-07 14:18 UTC (permalink / raw)
To: cygwin-patches
On Aug 6 20:03, Jon Turney wrote:
> On 04/08/2024 22:48, Jon Turney wrote:
> > Supress new use-after-free warnings about realloc(), seen with gcc 12, e.g.:
> >
> > > In function ‘void rebase_locale_buf(const void*, const void*, const char*, const char*, const char*)’,
> > > inlined from ‘int __set_lc_time_from_win(const char*, const lc_time_T*, lc_time_T*, char**, wctomb_p, const char*)’ at ../../../../src/winsup/cygwin/nlsfuncs.cc:705:25:
> > > ../../../../src/winsup/cygwin/nlsfuncs.cc:338:24: error: pointer ‘new_lc_time_buf’ may be used after ‘void* realloc(void*, size_t)’ [-Werror=use-after-free]
> > > 338 | *ptrs += newbase - oldbase;
> > > | ~~~~~~~~^~~~~~~~~
> > > ../../../../src/winsup/cygwin/nlsfuncs.cc: In function ‘int __set_lc_time_from_win(const char*, const lc_time_T*, lc_time_T*, char**, wctomb_p, const char*)’:
> > > ../../../../src/winsup/cygwin/nlsfuncs.cc:699:44: note: call to ‘void* realloc(void*, size_t)’ here
> > > 699 | char *tmp = (char *) realloc (new_lc_time_buf, len);
> >
> > We do some calculations using the pointer passed to realloc(), but do
> > not not dereference it, so this seems safe?
> Since this is less than ideal, here's the version where we explicitly
> malloc() the new buffer, adjust things, then free() the old buffer.
>
> This is all quite hairy, though, and I have no idea how to begin to test
> this, so if you have some pointers to share, that would be good.
No pointers as such, but tcsh uses it's own allocator, while bash
doesn't. So testing involves running bash and tcsh and then changing
LC_ALL to any odd (but existing) locale, e.g.
en_US, de_DE.utf8, fa_IR, fa_IR.utf8, zh_HK, zh_HK.utf8, you name it
bash$ export LC_ALL=foo
tcsh$ setenv LC_ALL foo
This shoudn't crash bash nor tcsh.
FWIW, your patch looks right to me.
Thanks,
Corinna
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 5/6] Cygwin: Fix warnings about narrowing conversions of socket ioctls
2024-08-07 14:06 ` Corinna Vinschen
@ 2024-08-11 18:31 ` Brian Inglis
2024-08-11 21:37 ` Brian Inglis
0 siblings, 1 reply; 18+ messages in thread
From: Brian Inglis @ 2024-08-11 18:31 UTC (permalink / raw)
To: cygwin-patches
[-- Attachment #1: Type: text/plain, Size: 2989 bytes --]
On 2024-08-07 08:06, Corinna Vinschen wrote:
> On Aug 6 19:58, Jon Turney wrote:
>> On 05/08/2024 11:22, Corinna Vinschen wrote:
>>> On Aug 4 22:48, Jon Turney wrote:
>>>> Fix gcc 12 warnings about narrowing conversions of socket ioctl constants
>>>> when used as case labels, e.g:
>>>> [...]
>>> The only caller, fhandler_socket::ioctl, passes an unsigned int
>>> value to get_ifconf. Given how the value is defined, it would be
>>> more straightforward to convert get_ifconf to
>>>
>>> get_ifconf (struct ifconf *ifc, unsigned int what);
>>>
>>> wouldn't it?
>>
>> Yeah, I'm not sure why I didn't do that. I think I got confused about where
>> this is used from.
> LGTM. I will additionally push a patch dropping the useless casts.
Hi folks,
Trying to rebuild got a couple of issues with gcc12 and likely recent updates to
main, as my previous rebuild for /proc/cpuinfo with gcc11 was fine:
- picky g++
CXX net.o
In file included from
/usr/src/newlib-cygwin/winsup/cygwin/include/cygwin/socket.h:47,
from /usr/src/newlib-cygwin/winsup/cygwin/include/cygwin/if.h:17,
from /usr/src/newlib-cygwin/winsup/cygwin/include/ifaddrs.h:42,
from /usr/src/newlib-cygwin/winsup/cygwin/net.cc:26:
/usr/src/newlib-cygwin/winsup/cygwin/net.cc: In function ‘int
get_ifconf(ifconf*, int)’:
/usr/src/newlib-cygwin/winsup/cygwin/net.cc:1940:18: error: narrowing conversion
of ‘2152756069’ from ‘long unsigned int’ to ‘int’ [-Wnarrowing]
1940 | case SIOCGIFFLAGS:
| ^~~~~~~~~~~~
... and so on
50cf10dfa485 Cygwin: asm/socket.h: drop outdated casts
so change net.cc get_ifconf (struct ifconf *ifc, int what) to unsigned long, and
where it is also declared in fhandler/socket.cc?
- __utoa (and __itoa) declared in stdlib.h inside #ifndef __CYGWIN__
CC libc/stdlib/libc_a-itoa.o
/usr/src/newlib-cygwin/newlib/libc/stdlib/itoa.c: In function ‘__itoa’:
/usr/src/newlib-cygwin/newlib/libc/stdlib/itoa.c:57:3: warning: implicit
declaration of function ‘__utoa’; did you mean ‘__itoa’?
[-Wimplicit-function-declaration]
57 | __utoa (uvalue, &str[i], base);
| ^~~~~~
| __itoa
31f7cd1e4332 Hide itoa, utoa, __itoa and __utoa in stdlib.h on Cygwin only
$ grep -C2 utoa ../../newlib/libc/include/stdlib.h
#ifndef __CYGWIN__
char * __itoa (int, char *, int);
char * __utoa (unsigned, char *, int);
# if __MISC_VISIBLE
char * itoa (int, char *, int);
char * utoa (unsigned, char *, int);
# endif
#endif
so should this be __INSIDE_CYGWIN__ instead or something else?
--
Take care. Thanks, Brian Inglis Calgary, Alberta, Canada
La perfection est atteinte Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer but when there is no more to cut
-- Antoine de Saint-Exupéry
[-- Attachment #2: newlib-cygwin-build64-gcc-12-issues.log --]
[-- Type: text/plain, Size: 5750 bytes --]
2024-08-10 22:01:35Z
2024-08-10 22:01:36Z
2024-08-10 22:04:02Z
...
make[2]: Entering directory '/usr/src/build64/x86_64-pc-cygwin/newlib'
/usr/bin/make "CC_FOR_BUILD=gcc" "CFLAGS=-g -O2" "CCASFLAGS=-g -O2" "CFLAGS_FOR_BUILD=-g -O2" "CFLAGS_FOR_TARGET=-g -O2" "INSTALL=/usr/bin/install -c" "LDFLAGS=" "LIBCFLAGS=-g -O2" "LIBCFLAGS_FOR_TARGET=-g -O2" "MAKE=/usr/bin/make" "MAKEINFO=makeinfo --split-size=5000000 --split-size=5000000 " "PICFLAG=" "PICFLAG_FOR_TARGET=" "SHELL=/bin/sh" "EXPECT=expect" "RUNTEST=runtest" "RUNTESTFLAGS=" "exec_prefix=/usr/src/install64/usr/bin" "infodir=/usr/src/install64/usr/share/info" "libdir=/usr/src/install64/usr/bin/lib" "prefix=/usr/src/install64/usr" "tooldir=/usr/src/install64/usr/bin/x86_64-pc-cygwin" "top_toollibdir=/usr/src/install64/usr/bin/x86_64-pc-cygwin/lib" "AR=ar " "AS=as" "CC=gcc -L/usr/src/build64/x86_64-pc-cygwin/winsup/cygwin -isystem /usr/src/newlib-cygwin/winsup/cygwin/include -B/usr/src/build64/x86_64-pc-cygwin/newlib/ -isystem /usr/src/build64/x86_64-pc-cygwin/newlib/targ-include -isystem /usr/src/newlib-cygwin/newlib/libc/include -I/usr/src/newlib-cygwin/newlib/../winsup/cygwin/include" "LD=/usr/lib/gcc/x86_64-pc-cygwin/12/../../../../x86_64-pc-cygwin/bin/ld.exe" "LIBCFLAGS=-g -O2" "NM=nm" "PICFLAG=" "RANLIB=ranlib " "DESTDIR=/usr/src/install64" all-am
make[3]: Entering directory '/usr/src/build64/x86_64-pc-cygwin/newlib'
...
CC libc/stdlib/libc_a-itoa.o
/usr/src/newlib-cygwin/newlib/libc/stdlib/itoa.c: In function ‘__itoa’:
/usr/src/newlib-cygwin/newlib/libc/stdlib/itoa.c:57:3: warning: implicit declaration of function ‘__utoa’; did you mean ‘__itoa’? [-Wimplicit-function-declaration]
57 | __utoa (uvalue, &str[i], base);
| ^~~~~~
| __itoa
...
make[4]: Leaving directory '/usr/src/build64/x86_64-pc-cygwin/newlib'
make[3]: Leaving directory '/usr/src/build64/x86_64-pc-cygwin/newlib'
make[2]: Leaving directory '/usr/src/build64/x86_64-pc-cygwin/newlib'
make[2]: Entering directory '/usr/src/build64/x86_64-pc-cygwin/winsup'
make[3]: Entering directory '/usr/src/build64/x86_64-pc-cygwin/winsup/cygwin'
make[4]: Entering directory '/usr/src/build64/x86_64-pc-cygwin/winsup/cygwin'
...
CXX net.o
In file included from /usr/src/newlib-cygwin/winsup/cygwin/include/cygwin/socket.h:47,
from /usr/src/newlib-cygwin/winsup/cygwin/include/cygwin/if.h:17,
from /usr/src/newlib-cygwin/winsup/cygwin/include/ifaddrs.h:42,
from /usr/src/newlib-cygwin/winsup/cygwin/net.cc:26:
/usr/src/newlib-cygwin/winsup/cygwin/net.cc: In function ‘int get_ifconf(ifconf*, int)’:
/usr/src/newlib-cygwin/winsup/cygwin/net.cc:1940:18: error: narrowing conversion of ‘2152756069’ from ‘long unsigned int’ to ‘int’ [-Wnarrowing]
1940 | case SIOCGIFFLAGS:
| ^~~~~~~~~~~~
/usr/src/newlib-cygwin/winsup/cygwin/net.cc:1943:18: error: narrowing conversion of ‘2148561764’ from ‘long unsigned int’ to ‘int’ [-Wnarrowing]
1943 | case SIOCGIFCONF:
| ^~~~~~~~~~~
/usr/src/newlib-cygwin/winsup/cygwin/net.cc:1944:18: error: narrowing conversion of ‘2152756070’ from ‘long unsigned int’ to ‘int’ [-Wnarrowing]
1944 | case SIOCGIFADDR:
| ^~~~~~~~~~~
/usr/src/newlib-cygwin/winsup/cygwin/net.cc:1948:18: error: narrowing conversion of ‘2152756072’ from ‘long unsigned int’ to ‘int’ [-Wnarrowing]
1948 | case SIOCGIFNETMASK:
| ^~~~~~~~~~~~~~
/usr/src/newlib-cygwin/winsup/cygwin/net.cc:1952:18: error: narrowing conversion of ‘2152756078’ from ‘long unsigned int’ to ‘int’ [-Wnarrowing]
1952 | case SIOCGIFDSTADDR:
| ^~~~~~~~~~~~~~
/usr/src/newlib-cygwin/winsup/cygwin/net.cc:1959:18: error: narrowing conversion of ‘2152756071’ from ‘long unsigned int’ to ‘int’ [-Wnarrowing]
1959 | case SIOCGIFBRDADDR:
| ^~~~~~~~~~~~~~
/usr/src/newlib-cygwin/winsup/cygwin/net.cc:1970:18: error: narrowing conversion of ‘2152756073’ from ‘long unsigned int’ to ‘int’ [-Wnarrowing]
1970 | case SIOCGIFHWADDR:
| ^~~~~~~~~~~~~
/usr/src/newlib-cygwin/winsup/cygwin/net.cc:1974:18: error: narrowing conversion of ‘2152756074’ from ‘long unsigned int’ to ‘int’ [-Wnarrowing]
1974 | case SIOCGIFMETRIC:
| ^~~~~~~~~~~~~
/usr/src/newlib-cygwin/winsup/cygwin/net.cc:1977:18: error: narrowing conversion of ‘2152756075’ from ‘long unsigned int’ to ‘int’ [-Wnarrowing]
1977 | case SIOCGIFMTU:
| ^~~~~~~~~~
/usr/src/newlib-cygwin/winsup/cygwin/net.cc:1980:18: error: narrowing conversion of ‘2152756076’ from ‘long unsigned int’ to ‘int’ [-Wnarrowing]
1980 | case SIOCGIFINDEX:
| ^~~~~~~~~~~~
/usr/src/newlib-cygwin/winsup/cygwin/net.cc:1983:18: error: narrowing conversion of ‘2152756077’ from ‘long unsigned int’ to ‘int’ [-Wnarrowing]
1983 | case SIOCGIFFRNDLYNAM:
| ^~~~~~~~~~~~~~~~
make[4]: *** [Makefile:2076: net.o] Error 1
make[4]: Leaving directory '/usr/src/build64/x86_64-pc-cygwin/winsup/cygwin'
make[3]: *** [Makefile:1186: all] Error 2
make[3]: Leaving directory '/usr/src/build64/x86_64-pc-cygwin/winsup/cygwin'
make[2]: *** [Makefile:395: all-recursive] Error 1
make[2]: Leaving directory '/usr/src/build64/x86_64-pc-cygwin/winsup'
make[1]: *** [Makefile:9464: all-target-winsup] Error 2
make[1]: Leaving directory '/usr/src/build64'
make: *** [Makefile:883: all] Error 2
2024-08-10 22:23:31Z
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 5/6] Cygwin: Fix warnings about narrowing conversions of socket ioctls
2024-08-11 18:31 ` Brian Inglis
@ 2024-08-11 21:37 ` Brian Inglis
0 siblings, 0 replies; 18+ messages in thread
From: Brian Inglis @ 2024-08-11 21:37 UTC (permalink / raw)
To: cygwin-patches
On 2024-08-11 12:31, Brian Inglis wrote:
> On 2024-08-07 08:06, Corinna Vinschen wrote:
>> On Aug 6 19:58, Jon Turney wrote:
>>> On 05/08/2024 11:22, Corinna Vinschen wrote:
>>>> On Aug 4 22:48, Jon Turney wrote:
>>>>> Fix gcc 12 warnings about narrowing conversions of socket ioctl constants
>>>>> when used as case labels, e.g:
>>>>> [...]
>>>> The only caller, fhandler_socket::ioctl, passes an unsigned int
>>>> value to get_ifconf. Given how the value is defined, it would be
>>>> more straightforward to convert get_ifconf to
>>>>
>>>> get_ifconf (struct ifconf *ifc, unsigned int what);
>>>>
>>>> wouldn't it?
>>>
>>> Yeah, I'm not sure why I didn't do that. I think I got confused about where
>>> this is used from.
>
>> LGTM. I will additionally push a patch dropping the useless casts.
>
> Hi folks,
>
> Trying to rebuild got a couple of issues with gcc12 and likely recent updates to
> main, as my previous rebuild for /proc/cpuinfo with gcc11 was fine:
>
> - picky g++
>
> CXX net.o
> In file included from
> /usr/src/newlib-cygwin/winsup/cygwin/include/cygwin/socket.h:47,
> from /usr/src/newlib-cygwin/winsup/cygwin/include/cygwin/if.h:17,
> from /usr/src/newlib-cygwin/winsup/cygwin/include/ifaddrs.h:42,
> from /usr/src/newlib-cygwin/winsup/cygwin/net.cc:26:
> /usr/src/newlib-cygwin/winsup/cygwin/net.cc: In function ‘int
> get_ifconf(ifconf*, int)’:
> /usr/src/newlib-cygwin/winsup/cygwin/net.cc:1940:18: error: narrowing conversion
> of ‘2152756069’ from ‘long unsigned int’ to ‘int’ [-Wnarrowing]
> 1940 | case SIOCGIFFLAGS:
> | ^~~~~~~~~~~~
> ... and so on
>
> 50cf10dfa485 Cygwin: asm/socket.h: drop outdated casts
>
> so change net.cc get_ifconf (struct ifconf *ifc, int what) to unsigned long, and
> where it is also declared in fhandler/socket.cc?
>
> - __utoa (and __itoa) declared in stdlib.h inside #ifndef __CYGWIN__
>
> CC libc/stdlib/libc_a-itoa.o
> /usr/src/newlib-cygwin/newlib/libc/stdlib/itoa.c: In function ‘__itoa’:
> /usr/src/newlib-cygwin/newlib/libc/stdlib/itoa.c:57:3: warning: implicit
> declaration of function ‘__utoa’; did you mean ‘__itoa’?
> [-Wimplicit-function-declaration]
> 57 | __utoa (uvalue, &str[i], base);
> | ^~~~~~
> | __itoa
>
>
> 31f7cd1e4332 Hide itoa, utoa, __itoa and __utoa in stdlib.h on Cygwin only
>
> $ grep -C2 utoa ../../newlib/libc/include/stdlib.h
> #ifndef __CYGWIN__
> char * __itoa (int, char *, int);
> char * __utoa (unsigned, char *, int);
> # if __MISC_VISIBLE
> char * itoa (int, char *, int);
> char * utoa (unsigned, char *, int);
> # endif
> #endif
>
> so should this be __INSIDE_CYGWIN__ instead or something else?
Sorry folks,
Did not notice patches 5-6/6 have not yet been applied.
Apply both okay and rebuild proceeding.
--
Take care. Thanks, Brian Inglis Calgary, Alberta, Canada
La perfection est atteinte Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer but when there is no more to cut
-- Antoine de Saint-Exupéry
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2024-08-11 21:37 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-04 21:48 [PATCH 0/6] Fix/supress warnings with gcc 12 Jon Turney
2024-08-04 21:48 ` [PATCH 1/6] Cygwin: Suppress array-bounds warning from NtCurrentTeb() Jon Turney
2024-08-05 10:11 ` Corinna Vinschen
2024-08-04 21:48 ` [PATCH 2/6] Cygwin: Fix warnings about narrowing conversions of NTSTATUS constants Jon Turney
2024-08-05 10:11 ` Corinna Vinschen
2024-08-04 21:48 ` [PATCH 3/6] Cygwin: Fix warning about address known to be non-NULL in /proc/locales Jon Turney
2024-08-05 10:18 ` Corinna Vinschen
2024-08-04 21:48 ` [PATCH 4/6] Cygwin: Fix warning about narrowing conversions in tape options Jon Turney
2024-08-05 10:18 ` Corinna Vinschen
2024-08-04 21:48 ` [PATCH 5/6] Cygwin: Fix warnings about narrowing conversions of socket ioctls Jon Turney
2024-08-05 10:22 ` Corinna Vinschen
2024-08-06 18:58 ` Jon Turney
2024-08-07 14:06 ` Corinna Vinschen
2024-08-11 18:31 ` Brian Inglis
2024-08-11 21:37 ` Brian Inglis
2024-08-04 21:48 ` [PATCH 6/6] Cygwin: Suppress false positive use-after-free warnings in __set_lc_time_from_win() Jon Turney
2024-08-06 19:03 ` Jon Turney
2024-08-07 14:18 ` Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).