1

I have the following source code and there is one line, which i cannot understand the casting is been made. Can anyone explain please? I know the casting to an integer pointer (int *) but this is different. I cannot understand what the final line does. Is it returning an integer pointer? or i am wrong?

const unsigned char sc[] =  {  0x01, 0x01, 0x01, 0x01   };
return ((int (*)(void))sc)();
3
  • Why don't you see the function definition and check what is it's return type? Commented Mar 6, 2015 at 14:47
  • the function prototype is the int main(), but i was looking forward to understand the meaning of the line and not only what returns Commented Mar 6, 2015 at 14:49
  • Is it working at all? Looks really weird. It calls an array as a function, while the array contents look nothing like executable code.. Commented Mar 6, 2015 at 14:58

1 Answer 1

4

(int (*)(void))sc takes address of an array sc and converts it to a pointer to function which returns int.

() at the end then calls this function, and return value of this function (type int) is again returned.

Weird part is that it seems as if the intention was to call function at address 0x01010101, but it uses the address of array sc instead, which may be an error.

Sign up to request clarification or add additional context in comments.

2 Comments

Not it seems very logic to me now. That's the source code. exploit-db.com/exploits/21252. Thank you!
Ah, so the original array is different.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.