public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Christian Franke <Christian.Franke@t-online.de>
To: cygwin@cygwin.com
Subject: [PATCH] cygutils-extra 1.4.16-3: cygdrop: Fix crash
Date: Sat, 14 Aug 2021 15:39:15 +0200	[thread overview]
Message-ID: <2f5eedb0-b3ec-4c4e-5740-5196e2572dc7@t-online.de> (raw)

[-- 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


                 reply	other threads:[~2021-08-14 13:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2f5eedb0-b3ec-4c4e-5740-5196e2572dc7@t-online.de \
    --to=christian.franke@t-online.de \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).