The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
segmentation fault rockgal High Level Programming 8 12-05-2006 08:16 AM
Segmentation Fault compbug UNIX for Dummies Questions & Answers 3 04-21-2006 07:43 AM
segmentation fault wojtyla High Level Programming 3 02-19-2005 10:53 AM
Segmentation fault jshaulis AIX 1 06-01-2004 01:16 PM
segmentation fault omran High Level Programming 2 08-01-2003 05:19 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #15 (permalink)  
Old 05-13-2008
Registered User
 

Join Date: May 2008
Posts: 26
Stumble this Post!
Thanks!

Thanks!

I was editing the assembly code generated by "gcc -S" and I realized that:

If I define in the main function a buffer as follows

char[8]

the first four lines in the assembly code are:

pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp

but if I change it by

char[9]

I get

pushl %ebp
movl %esp, %ebp
subl $24, %esp
andl $-16, %esp


and if I change it by

char[17]

I get

pushl %ebp
movl %esp, %ebp
subl $40, %esp
andl $-16, %esp

and so on.

I think the size of the stack depends on the compiler. Every 8 bytes I request, the compiler allocates 16 more.

It is right??

Please tell me if I'm being stupid!

Thank you very much for your support!
Reply With Quote
Forum Sponsor
  #16 (permalink)  
Old 05-13-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Stumble this Post!
In a way, I'm getting the feeling you are on the wrong track. I mean yes, you have reached useful insights about how a particular version of a particular compiler allocates and manages memory, but if as you were saying a few posts back the driver is that you need to explain to your management why you want to fix insecure code ... I'd be looking for a different employer, or hit them over the head with Smashing the Stack for Fun and Profit by Aleph One
Reply With Quote
  #17 (permalink)  
Old 05-13-2008
Registered User
 

Join Date: May 2008
Posts: 26
Stumble this Post!
Hi

You are right era! I'm going to explain to my boss how to work a stack overflow bug and all its consequences.

Thanks all of you!!
Reply With Quote
  #18 (permalink)  
Old 05-13-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 541
Stumble this Post!
Note that it's not a stack overflow bug but the fact that sprintf() does not check for bounds which causes the routine to overflow its frame.
Reply With Quote
  #19 (permalink)  
Old 05-13-2008
Registered User
 

Join Date: May 2008
Posts: 26
Stumble this Post!
Hi

I mean the program that I'm fixing has a buffer overflow bug, because don't validates the length of string! Thanks a lot for your support!
Reply With Quote
  #20 (permalink)  
Old 05-20-2008
Registered User
 

Join Date: Mar 2008
Location: Delhi
Posts: 7
Stumble this Post!
Let me add sth...
When some object is created say Char arr[MAX].. that is always be the part of some Segment and if the Object is occupying less than 512 bytes
Then its default segment would be of 512 bytes.So for a char arr[10] bytes we can go upto 502 bytes.That is why no segment in the case.
Reply With Quote
  #21 (permalink)  
Old 05-20-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 541
Stumble this Post!
Quote:
Originally Posted by unisuraj View Post
Let me add sth...
When some object is created say Char arr[MAX].. that is always be the part of some Segment and if the Object is occupying less than 512 bytes
Then its default segment would be of 512 bytes.So for a char arr[10] bytes we can go upto 502 bytes.That is why no segment in the case.
You are confusing disk block allocation with memory page allocation.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0