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

  • Home
  • SEARCH
  • 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 6685079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:00:55+00:00 2026-05-26T05:00:55+00:00

I have a program for which I wanted to understand the state the stack

  • 0

I have a program for which I wanted to understand the state the stack will be during its execution. My sample program is simple enough,

#include <stdio.h>
 int main(){
   setuid(0);
   system("/bin/bash");
   return 1;
 }

Now when I debug this program with gdb I get the address of setuid() function but when I look at the stack I am not able to figure its address.

My stack’s state after starting to execute main(),

Ajai@ubuntu:/tmp$ gdb -q mal
Reading symbols from /tmp/mal...done.
(gdb) b 2
Breakpoint 1 at 0x80483fd: file mal.c, line 2.
(gdb) r
Starting program: /tmp/mal 

Breakpoint 1, main () at mal.c:4
4        setuid(0);
(gdb) x/32xw $esp
0xbffff3a0:    0x0015ed35    0x0011ea50    0x0804842b    0x0028bff4
0xbffff3b0:    0x08048420    0x00000000    0xbffff438    0x00145e37
0xbffff3c0:    0x00000001    0xbffff464    0xbffff46c    0x0012e414
0xbffff3d0:    0xffffffff    0x0012cff4    0x08048243    0x00000001
0xbffff3e0:    0xbffff420    0x0011da31    0x0012dad0    0xb7fffb48
0xbffff3f0:    0x00000001    0x0028bff4    0x00000000    0x00000000
0xbffff400:    0xbffff438    0xb68cac87    0x61d0d5f8    0x00000000
0xbffff410:    0x00000000    0x00000000    0x00000001    0x08048340
(gdb) p setuid
$1 = {<text variable, no debug info>} 0x1c8ee0 <setuid>

Am I looking at the stack wrong ?

I also wanted to know how will the address of setuid() function call and its parameter and system() function call and its parameter will be stored in the stack when main() function starts to execute.

I am sorry if this kind of question has already been asked but I could not find one.

  • 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-05-26T05:00:56+00:00Added an answer on May 26, 2026 at 5:00 am

    Your question is exceedingly unclear, likely because you do not understand how stack and calls work and interact.

    Somehow you are expecting to find the address of setuid on the stack before that function has been called. But that address wouldn’t be there at all (neither before the call, nor while the call is in progress, nor after it has finished).

    If you set a breakpoint on setuid itself, run to that breakpoint, and examine the stack. Then, you’ll see the address in main (not of main itself, but of the instruction in main that follows the CALL instruction that got you into setuid in the first place).

    I assume this is how stack looks like when execution is about to go to setuid() function (assuming I have a breakpoint at setuid function call)

    1.call to setuid()

    2.return address to be reached after setuid() function call

    3.parameters to setuid() function.

    As I said, your assumptions are incorrect: there is no "call to setuid" on the stack (but 2. and 3. are correct).

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

Sidebar

Related Questions

I have a program which runs on a console and its Umlauts and other
I have a C program which generates a series of images and I wanted
For a school project, I have a simple program, which compares 20x20 photos. I
I have an existing winform app which didn't use Program.cs. I wanted to add
I have a program which needs to behave slightly differently on Tiger than on
I have a program which deliberately performs a divide by zero (and stores the
I have a program which has some Textareas / Labels these can be anywhere
I have a program which needs installing on windows 64 boxes. Most of the
I have a program which only needs a NotifyIcon to work as intended. So
I have a program which I would like to run every X min the

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.