delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2021/08/14/09:40:07

X-Recipient: archive-cygwin AT delorie DOT com
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 96993385842E
Authentication-Results: sourceware.org;
dmarc=none (p=none dis=none) header.from=t-online.de
Authentication-Results: sourceware.org; spf=none smtp.mailfrom=t-online.de
From: Christian Franke <Christian DOT Franke AT t-online DOT de>
Subject: [PATCH] cygutils-extra 1.4.16-3: cygdrop: Fix crash
To: cygwin AT cygwin DOT com
Message-ID: <2f5eedb0-b3ec-4c4e-5740-5196e2572dc7@t-online.de>
Date: Sat, 14 Aug 2021 15:39:15 +0200
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101
SeaMonkey/2.53.8.1
MIME-Version: 1.0
X-ID: XNt28uZT8heA41igj4gjmkc3JZSm5ivZEaxb3N6LUUx9KBe+Ve5qIE8il2MdSg7Z61
X-TOI-EXPURGATEID: 150726::1628948355-0000454D-71799F73/0/0 CLEAN NORMAL
X-TOI-MSGID: 7079d114-0638-4348-acb1-f786fc2198ff
X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, BODY_8BITS,
FREEMAIL_FROM, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY,
KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,
RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE,
TXREP autolearn=ham autolearn_force=no version=3.4.4
X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on
server2.sourceware.org
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>

This is a multi-part message in MIME format.
--------------5943301D8A0BAF042EC8E242
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable

Cygdrop from recent cygutils-extra crashes (only) after printing help tex=
t:

$ cygdrop
Usage: cygdrop [OPTIONS] COMMAND [ARG ...]

Group options
 =C2=A0 -l=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Disable local admini=
strator group [default]
...
 =C2=A0 -v=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Verbose output, list=
s groups and privileges changed.
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Repea=
t 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=20
function return type was declared as 'int' instead of 'void':
https://sourceware.org/git/?p=3Dcygwin-apps/cygutils.git;a=3Dcommitdiff;h=
=3D517cf61

Newer g++ may then optimize away the function epilogue after inline=20
expansion. Here is a minimal testcase:

$ g++ --version
g++ (GCC) 10.2.0
...

$ cat test.cc
void f();

static int g()
{
 =C2=A0 f();
}

void h()
{
 =C2=A0 g();
}

$ g++ -S -O test.cc
test.cc: In function =E2=80=98int g()=E2=80=99:
test.cc:6:1: warning: no return statement in function returning non-void=20
[-Wreturn-type]
 =C2=A0=C2=A0=C2=A0 6 | }
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | ^

$ c++filt < test.s
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .file=C2=A0=C2=A0 "test.cc"
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .text
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .globl=C2=A0 h()
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .def=C2=A0=C2=A0=C2=A0 h();=C2=
=A0=C2=A0=C2=A0 .scl=C2=A0=C2=A0=C2=A0 2;=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .=
type=C2=A0=C2=A0 32; .endef
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .seh_proc=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 h()
h():
.LFB1:
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 subq=C2=A0=C2=A0=C2=A0 $40, %=
rsp
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .seh_stackalloc 40
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .seh_endprologue
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 call=C2=A0=C2=A0=C2=A0 f()
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 nop
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .seh_endproc
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .ident=C2=A0 "GCC: (GNU) 10.2=
.0"
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .def=C2=A0=C2=A0=C2=A0 f();=C2=
=A0=C2=A0=C2=A0 .scl=C2=A0=C2=A0=C2=A0 2;=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .=
type=C2=A0=C2=A0 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:
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 subq=C2=A0=C2=A0=C2=A0 $40, %=
rsp
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .seh_stackalloc 40
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .seh_endprologue
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 call=C2=A0=C2=A0=C2=A0 f
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 nop
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 addq=C2=A0=C2=A0=C2=A0 $40, %=
rsp
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .seh_endproc
...


The problem also occurs with 32-bit Cygwin g++ and with current=20
MinGW-w64-g++ 32/64-bit.

Unfortunately GCC upstream has already set a related bug report to INVALI=
D:
 =C2=A0https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96181
I disagree...

Cygport should possibly add '-Werror=3Dreturn-type' to C++ defaults.


Patch for cygutils is attached.

Regards,
Christian


--------------5943301D8A0BAF042EC8E242
Content-Type: text/plain; charset=UTF-8;
 name="0001-cygdrop-Fix-return-type-of-void-function.patch"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename="0001-cygdrop-Fix-return-type-of-void-function.patch"

RnJvbSAzMzBlNGM4MDMzZWExN2MzMTI4Njc5MDYwOTIzOTc0MjVkOTc3YzA3IE1vbiBTZXAg
MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBDaHJpc3RpYW4gRnJhbmtlIDxjaHJpc3RpYW4uZnJh
bmtlQHQtb25saW5lLmRlPgpEYXRlOiBTYXQsIDE0IEF1ZyAyMDIxIDE0OjMyOjI1ICswMjAw
ClN1YmplY3Q6IFtQQVRDSF0gY3lnZHJvcDogRml4IHJldHVybiB0eXBlIG9mICd2b2lkJyBm
dW5jdGlvbi4KClRoaXMgZml4ZXMgYSBjcmFzaCB3aXRoIHJlY2VudCB2ZXJzaW9ucyBvZiBn
KysgKEdDQyBCdWd6aWxsYSA5NjE4MSkuCi0tLQogc3JjL2N5Z2Ryb3AvY3lnZHJvcC5jYyB8
IDIgKy0KIDEgZmlsZSBjaGFuZ2VkLCAxIGluc2VydGlvbigrKSwgMSBkZWxldGlvbigtKQoK
ZGlmZiAtLWdpdCBhL3NyYy9jeWdkcm9wL2N5Z2Ryb3AuY2MgYi9zcmMvY3lnZHJvcC9jeWdk
cm9wLmNjCmluZGV4IDM1YmNjMTkuLmRjNDAzYzkgMTAwNjQ0Ci0tLSBhL3NyYy9jeWdkcm9w
L2N5Z2Ryb3AuY2MKKysrIGIvc3JjL2N5Z2Ryb3AvY3lnZHJvcC5jYwpAQCAtMzksNyArMzks
NyBAQCBzdGF0aWMgdm9pZCBoZWxwIChGSUxFICogZiwgY29uc3QgY2hhciAqbmFtZSk7CiBz
dGF0aWMgdm9pZCB2ZXJzaW9uIChGSUxFICogZiwgY29uc3QgY2hhciAqbmFtZSk7CiBzdGF0
aWMgdm9pZCBsaWNlbnNlIChGSUxFICogZiwgY29uc3QgY2hhciAqbmFtZSk7CiAKLXN0YXRp
YyBpbnQKK3N0YXRpYyB2b2lkCiB1c2FnZUNvcmUgKEZJTEUgKiBmLCBjb25zdCBjaGFyICog
bmFtZSkKIHsKICAgZnByaW50ZiAoZiwKLS0gCjIuMzIuMAoK
--------------5943301D8A0BAF042EC8E242
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

--------------5943301D8A0BAF042EC8E242--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019