Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

Just out of curiosity


ellipsis's Avatar
...
0 -1

The following code prints all environment variables among other things..

Can someone please elaborate to me why that is?

#include <iostream>
using namespace std;

string * GetArray()
{
    string asdf[3] = { "aaaaaaaa", "aaaaaaaa", "aaaaaaaa" };
    return(asdf);
}

void foo(string array[], int size)
{
//    for (int i = size; i >= 0; i--)  /* for a different exception */
        cout << array[1] << endl;
}

int main()
{
    string * array = GetArray();
    foo(array, 2); // <-- required for error
    
    return(0);
}

ghost's Avatar
0 0

It's full of errors and won't compile. Besides, you're returning the address of a local variable. When you get out of the function, we're not sure what the pointer is pointing to. if I were you, I'd disassemble it and look at the value dereferenced by the pointer after the function call completes. Maybe it's a list of environment variables?


hellboundhackersok's Avatar
Banned
0 0

ellipsis wrote: The following code prints all environment variables among other things..

Can someone please elaborate to me why that is?

It doesn't.