user1241223
user1241223

Reputation: 35

Passing arg 2 of `memset' makes integer from pointer without a cast

I am following a tutorial on http://www.corelan.be/index.php/2009/07/19/exploit-writing-tutorial-part-1-stack-based-overflows/ to learn more about exploits. The scripts shown are in perl and I wanted to write it in C I'm having trouble finding a function similar to "\x41" * 10000 in C. I looked around and found memset to be an option but when I use it I keep getting this error whether I was "A" or "\x41" as the 2nd argument. Here is my code:

#include <string.h>
#include <stdio.h>

int main(void)
{
    FILE *crash;
    crash = fopen("crash.m3u", "w+");
    char junk[10001];
    memset(junk, "A", sizeof(junk));
    fputs(junk, crash);
    fclose(crash);
    return 0;
}

Upvotes: 2

Views: 4850

Answers (3)

Ed Heal
Ed Heal

Reputation: 59997

Instead of a string, you need a character.

Try `\x41' instead of "A" - as given in the web page

Upvotes: 0

Matt Kline
Matt Kline

Reputation: 10487

"A" resolves to a string, or char*, but the second parameter of memset is an int. Using

memset(junk, 'A', sizeof(junk));

will work since 'A' is of type char, which can be implicitly cast into an int.

Upvotes: 1

Greg Hewgill
Greg Hewgill

Reputation: 993085

Use

memset(junk, 'A', sizeof(junk));

In C, there is a huge difference between single quotes ' and double quotes ". Single quotes are used for char values, and double quotes are used for string (multiple character, or const char *) values.

Upvotes: 6

Related Questions