Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8120271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:05:46+00:00 2026-06-06T05:05:46+00:00

I’m playing with one stack overflow example. This example looks like this: void return_input

  • 0

I’m playing with one stack overflow example. This example looks like this:

 void return_input (void){ 
    char array[30];    
    gets (array); 
    printf("%s\n", array); 

 }

 main() { 
    return_input();    
    return 0;    
 }

All this code is in the file called overflow.c. We have vulnerable function called return_input, particularly it’s 30 byte char array. I compiled it and opened vulnerable function in gdb and got following output:

 (gdb) disas return_input
 0x08048464 <+0>:   push   %ebp
 0x08048465 <+1>:   mov    %esp,%ebp
 0x08048467 <+3>:   sub    $0x48,%esp
 0x0804846a <+6>:   mov    %gs:0x14,%eax
 0x08048470 <+12>:  mov    %eax,-0xc(%ebp)
 0x08048473 <+15>:  xor    %eax,%eax
 0x08048475 <+17>:  lea    -0x2a(%ebp),%eax
 0x08048478 <+20>:  mov    %eax,(%esp)
 0x0804847b <+23>:  call   0x8048360 <gets@plt>
 0x08048480 <+28>:  lea    -0x2a(%ebp),%eax
 0x08048483 <+31>:  mov    %eax,(%esp)
 0x08048486 <+34>:  call   0x8048380 <puts@plt>
 0x0804848b <+39>:  mov    -0xc(%ebp),%eax
 0x0804848e <+42>:  xor    %gs:0x14,%eax
 0x08048495 <+49>:  je     0x804849c <return_input+56>
 0x08048497 <+51>:  call   0x8048370 <__stack_chk_fail@plt>
 0x0804849c <+56>:  leave  
 0x0804849d <+57>:  ret    
 End of assembler dump.

As you see from the function prologue we reserved hex48(dec 72) bytes on the stack for local variables. First I was trying to find the address where our vulnerable array starts on the stack. I think it’s -0x2a(%ebp), am I right? Hex2a is 42 decimal. As I understand it means that we can write safely 42 bytes before we start to overwrite EBP saved on the stack. But when I run this example it’s enough to right only 37 bytes to get segmentation fault:

rustam@rustam-laptop:~/temp/ELF_reader$ ./overflow
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Segmentation fault (core dumped)

How is 37 bytes enough to overflow buffer? If our local char array is -42 bytes from saved EBP

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:05:47+00:00Added an answer on June 6, 2026 at 5:05 am

    It is hard to tell without seeing the whole disassembly of the function.

    However, my guess is that the %gs:0x14 stored at -0xc(%ebp) may be your stack canary that causes a clean exit if a stack coruption is detected.
    So this value is stored at -0xc(%ebp), which means that your buffer is in fact only 30 bytes large, followed by whatever comes after.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.