what am i looking at

what am i looking at

Post by pretentious on Thu Jun 20, 2013 5:19 am
([msg=76183]see what am i looking at[/msg])

I was playing around with C and put this together
Code: Select all
#include <stdio.h>
int main()
{
  char a = 'H';
  char b = 'T';
  short int c = (int)'S';
  int count;
  for(count = 0;; count++) // also works in reverse
  {
    printf("%c", *(&a+count));
  }
  return 0;
}

first i see a bunch or random data, which i expect, then a bunch of directory listings and stuff. Don't know what to make of it.
I take it that i'm looking at the stack and data left behind by something else and with the readable stuff, it has flowed into another part of memory before the segfault?
Could anyone enlighten me?
Goatboy wrote:Oh, that's simple. All you need to do is dedicate many years of your life to studying security.

IF you feel like exchanging ASCII arrays, let me know ;)
pretentious wrote:Welcome to bat country
User avatar
pretentious
Contributor
Contributor
 
Posts: 621
Joined: Wed Mar 03, 2010 12:48 am
Blog: View Blog (0)


Re: what am i looking at

Post by narveras on Fri Jun 21, 2013 10:51 am
([msg=76207]see Re: what am i looking at[/msg])

Ran it on my pc as well, just as you I get random characters and than directories,
The directories when I ran it though, were somewhat around the filepath of the exe i created when I compiled.
narveras
New User
New User
 
Posts: 1
Joined: Fri Jun 21, 2013 10:47 am
Blog: View Blog (0)


Re: what am i looking at

Post by centip3de on Sat Jun 22, 2013 1:00 pm
([msg=76218]see Re: what am i looking at[/msg])

pretentious wrote:I was playing around with C and put this together
Code: Select all
#include <stdio.h>
int main()
{
  char a = 'H';
  char b = 'T';
  short int c = (int)'S';
  int count;
  for(count = 0;; count++) // also works in reverse
  {
    printf("%c", *(&a+count));
  }
  return 0;
}

first i see a bunch or random data, which i expect, then a bunch of directory listings and stuff. Don't know what to make of it.
I take it that i'm looking at the stack and data left behind by something else and with the readable stuff, it has flowed into another part of memory before the segfault?
Could anyone enlighten me?


Just from looking at it, without running it through GDB or anything else, I'd say that you're right and it is running through the stacks readable memory. You have an infinite loop that is listing through all the memory addresses and printing out their data, I'm assuming eventually you'd hit the stack, or some other structure and are printing out it's data.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rick Cook
User avatar
centip3de
Moderator
Moderator
 
Posts: 1412
Joined: Fri Aug 20, 2010 5:46 pm
Blog: View Blog (0)



Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests