Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a const array #62

Closed
sploving opened this issue Aug 31, 2016 · 4 comments
Closed

Generate a const array #62

sploving opened this issue Aug 31, 2016 · 4 comments

Comments

@sploving
Copy link
Contributor

I want to generate a const array for the following struct in sys/tun.txt, for instance, "wlan0"
ifreq {
name array[int8, 16]
u ifr_ifru
}

I tried with strconst as the following, but it does not work as expected. The expected output should be a const char array filled "wlan0", But it generate a pointer to a buffer that contains the string.
ifreq {
name strconst["wlan0"]
pad array[const[0, int8], 10]
u ifr_ifru
}

The generated output is:
r[1] = syscall(SYS_mmap, 0x20000000ul, 0x1000ul, 0x3ul, 0x32ul, 0xfffffffffffffffful, 0x0ul);
(uint64_t)0x20000000 = (uint64_t)0x20000b81;
(uint64_t)0x20000008 = (uint64_t)0x0;
(uint16_t)0x20000010 = (uint16_t)0x0;
(uint64_t)0x20000020 = (uint64_t)0x20000ff0; // the address to ifr_ifru
memcpy((void*)0x20000b81, "\x77\x6c\x61\x6e\x30\x00", 6);

The expected output should be:
r[1] = syscall(SYS_mmap, 0x20000000ul, 0x1000ul, 0x3ul, 0x32ul, 0xfffffffffffffffful, 0x0ul);
memcpy((void_)0x20000000, "\x77\x6c\x61\x6e\x30\x00", 6);
*(uint64_t_)0x20000006 = (uint64_t)0x0;
(uint16_t)0x2000000e = (uint16_t)0x0;
(uint64_t)0x20000010 = (uint64_t)0x20000ff0;
Any suggestion? Thanks.

@dvyukov
Copy link
Collaborator

dvyukov commented Aug 31, 2016

There is no good support right now. There are several similar cases. The best thing you can do now is:

name0 const[119, int8]
name1 const[108, int8]
... same for 'a' 'n' '0'
namepad array[const[0, int8], 11]

If my math is correct, pad size must be 11, not 10.

@sploving
Copy link
Contributor Author

I tried with what you suggested. It panics:
panic: & arg is not a pointer: sys.ConstType{TypeCommon:sys.TypeCommon{TypeName:"name0", IsOptional:false}, TypeSize:0x1, Val:0x77, IsPad:false}
Does it mean that currently it only supports const 0?

@dvyukov
Copy link
Collaborator

dvyukov commented Aug 31, 2016

That's due to old programs in your corpus that still use the old signature. Ideally, the argument type mismatch should be detected and these programs automatically deleted. Filed #63 for this.

For now delete all program with syscalls that reference this type from corpus with:

$ grep -l "my_new_syscall" workdir/corpus | xargs rm {}

@dvyukov
Copy link
Collaborator

dvyukov commented Nov 13, 2016

Fixed by:
588a542
3a65453
5ed6283

@dvyukov dvyukov closed this as completed Nov 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants