[PATCH] cygutils-extra 1.4.16-3: cygdrop: Fix crash
Christian Franke
Christian.Franke@t-online.de
Sat Aug 14 13:39:15 GMT 2021
Cygdrop from recent cygutils-extra crashes (only) after printing help text:
$ cygdrop
Usage: cygdrop [OPTIONS] COMMAND [ARG ...]
Group options
-l Disable local administrator group [default]
...
-v Verbose output, lists groups and privileges changed.
Repeat to list all groups and privileges.
*** stack smashing detected ***: terminated
Aborted (core dumped)
The root of the problem is a usually harmless bug introduced in 2010. A
function return type was declared as 'int' instead of 'void':
https://sourceware.org/git/?p=cygwin-apps/cygutils.git;a=commitdiff;h=517cf61
Newer g++ may then optimize away the function epilogue after inline
expansion. Here is a minimal testcase:
$ g++ --version
g++ (GCC) 10.2.0
...
$ cat test.cc
void f();
static int g()
{
f();
}
void h()
{
g();
}
$ g++ -S -O test.cc
test.cc: In function ‘int g()’:
test.cc:6:1: warning: no return statement in function returning non-void
[-Wreturn-type]
6 | }
| ^
$ c++filt < test.s
.file "test.cc"
.text
.globl h()
.def h(); .scl 2; .type 32; .endef
.seh_proc h()
h():
.LFB1:
subq $40, %rsp
.seh_stackalloc 40
.seh_endprologue
call f()
nop
.seh_endproc
.ident "GCC: (GNU) 10.2.0"
.def f(); .scl 2; .type 32; .endef
Problem and -Wreturn-type do not occur if compiled as a C program:
$ g++ -xc -S -O test.cc
$ cat test.s
...
h:
subq $40, %rsp
.seh_stackalloc 40
.seh_endprologue
call f
nop
addq $40, %rsp
ret
.seh_endproc
...
The problem also occurs with 32-bit Cygwin g++ and with current
MinGW-w64-g++ 32/64-bit.
Unfortunately GCC upstream has already set a related bug report to INVALID:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96181
I disagree...
Cygport should possibly add '-Werror=return-type' to C++ defaults.
Patch for cygutils is attached.
Regards,
Christian
-------------- next part --------------
From 330e4c8033ea17c312867906092397425d977c07 Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Sat, 14 Aug 2021 14:32:25 +0200
Subject: [PATCH] cygdrop: Fix return type of 'void' function.
This fixes a crash with recent versions of g++ (GCC Bugzilla 96181).
---
src/cygdrop/cygdrop.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/cygdrop/cygdrop.cc b/src/cygdrop/cygdrop.cc
index 35bcc19..dc403c9 100644
--- a/src/cygdrop/cygdrop.cc
+++ b/src/cygdrop/cygdrop.cc
@@ -39,7 +39,7 @@ static void help (FILE * f, const char *name);
static void version (FILE * f, const char *name);
static void license (FILE * f, const char *name);
-static int
+static void
usageCore (FILE * f, const char * name)
{
fprintf (f,
--
2.32.0
More information about the Cygwin
mailing list