public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Lee <ler762@gmail.com>
To: cygwin@cygwin.com
Subject: Re: problem with i686-w64-mingw32-gcc -fstack-protector-all
Date: Thu, 05 Oct 2017 05:41:00 -0000	[thread overview]
Message-ID: <CAD8GWsu1CetVFeJPz4zxhZfDShQBQrHanzuyfuFu16VV=XxgDQ@mail.gmail.com> (raw)
In-Reply-To: <1d6ce5fb-ea05-b830-8096-98d839cc6e02@t-online.de>

On 10/4/17, Christian Franke   wrote:
> Lee wrote:
>> Maybe I'm just Doing It Wrong, but
>>    gcc -fstack-protector-all
>> seems to be working correctly &
>>    i686-w64-mingw32-gcc -fstack-protector-all
>> seems to be broken - eg:
>>
>> $./ssp testtestx
>> Illegal instruction
>>
>> printf's that happen before the stack over-write don't show up & no
>> "*** stack smashing detected ***" msg is printed before the "Illegal
>> instruction"
>> ...
>>
>> extern
>> int doit(char *s ) {
>>    char buf[]="12345678";
>>    int i=0;
>>    if ( *s != '\0' ) i = 1;  /* return true */
>>    printf("doit: s=\"%s\"   buf=\"%s\"  i=%d\n", s, buf, i );
>>    strcpy(buf, s);
>>      /* buffer overflow into return status(int i) if strlen(s) > 8 */
>>    printf("doit: s=\"%s\"   buf=\"%s\"  i=%d\n", s, buf, i );
>>    return i;
>> }
>>
>> + i686-w64-mingw32-gcc -c -fstack-protector-all func-ssp.c -o func-ssp.o
>> + i686-w64-mingw32-gcc -c -fstack-protector-all main-ssp.c -o main-ssp.o
>> + i686-w64-mingw32-gcc -static -o ssp.exe func-ssp.o main-ssp.o -lssp
>
> BTW: There is no need to link with -lssp if the related code generation
> option -fstack-protector* is also used during link.

Thanks for that!
I would have never guessed that a compile-time switch would have an
effect if all you're doing is linking.


>> + ./ssp.exe testtestx
>> ./doit: line 11:  9128 Illegal instruction     ./ssp.exe testtestx
>> + echo -e '\n\n'
>>
>
> The *** stack smashing detected *** message from MinGW runtime is only
> visible if stdio is attached to a Windows console.

Yes!
But even after re-reading https://github.com/mintty/mintty/wiki/Tips &
https://github.com/mintty/mintty/issues/56  I'm still missing why _no_
output is displayed before the 'Illegal instruction' output line.
Without a stack overflow I see:
$ ./ssp test
main: argv[1]=test
doit: s="test"   buf="12345678"  i=1
doit: s="test"   buf="test"  i=1
main: exit

so it seems like I should have gotten at least the first two lines of output.

> Works for me if one more overflow char is added:
>
> Cygwin mintty:
>
> $ ./ssp testtestx
> main: argv[1]=testtestx
> doit: s="testtestx"   buf="12345678"  i=1
> doit: s="testtestx"   buf="testtestx"  i=1
> main: exit

Interesting.  I have Windows 10 & i686-w64-mingw32-gcc (GCC) 6.3.0   you?


> $ ./ssp testtestxx
> Illegal instruction
>
>
> Cygwin in Windows console (cygwin.bat):
>
> $ ./ssp testtestxx
> main: argv[1]=testtestxx
> doit: s="testtestxx"   buf="12345678"  i=1
> doit: s="testtestxx"   buf="testtestxx"  i=1
> *** stack smashing detected ***:  terminated
> Illegal instruction
>
>
> cmd.exe in Windows console:
>
> C:\cygwin\tmp>.\ssp.exe testtestxx
> main: argv[1]=testtestxx
> doit: s="testtestxx"   buf="12345678"  i=1
> doit: s="testtestxx"   buf="testtestxx"  i=1
> *** stack smashing detected ***:  terminated
> [Windows Message Box: Debug/Abort Program ?]

I get the same with the cygwin.bat console window; a straight dos
(cmd.exe) console window has a 10 second delay after
*** stack smashing detected ***:  terminated
is displayed before I get the
   ------------------------
ssp.exe has stopped working

A problem caused the program to stop working
correctly. Please close the program.

 -> Close the program
   ------------------------
pop-up window

Anyway.. Thank you!!  It's been driving me nuts trying to figure out
why all I get is 'Illegal instruction'

Lee

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

  reply	other threads:[~2017-10-05  5:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-03 18:26 Lee
2017-10-04 19:18 ` Christian Franke
2017-10-05  5:41   ` Lee [this message]
2017-10-08 12:59     ` Christian Franke

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='CAD8GWsu1CetVFeJPz4zxhZfDShQBQrHanzuyfuFu16VV=XxgDQ@mail.gmail.com' \
    --to=ler762@gmail.com \
    --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).