public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] cygutils-extra 1.4.16-3: cygdrop: Fix crash
@ 2021-08-14 13:39 Christian Franke
  0 siblings, 0 replies; only message in thread
From: Christian Franke @ 2021-08-14 13:39 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 2314 bytes --]

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


[-- Attachment #2: 0001-cygdrop-Fix-return-type-of-void-function.patch --]
[-- Type: text/plain, Size: 792 bytes --]

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-14 13:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-14 13:39 [PATCH] cygutils-extra 1.4.16-3: cygdrop: Fix crash Christian Franke

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).