]> granicus.if.org Git - strace/commit
Fix decoding of sysctl() when oldval fields are NULL
authorMike Frysinger <vapier@gentoo.org>
Sat, 9 Feb 2013 00:10:07 +0000 (19:10 -0500)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 9 Feb 2013 01:39:43 +0000 (01:39 +0000)
commit0cf04b6595a951df7671eafef5f9e7a114a6c691
treea0d7cab133e269b2ccdb5f2f85a6cde58e749571
parent99aa181ebcee3f6ae4f8eb83c719cc64cc5a09ec
Fix decoding of sysctl() when oldval fields are NULL

If you call glibc's syscall wrapper like so:
static int name[] = { CTL_NET, NET_IPV4, NET_IPV4_LOCAL_PORT_RANGE };
int buffer[2] = { 32768, 61000 };
size_t size = sizeof(buffer);
sysctl(name, 3, 0, 0, buffer, size);
(note that oldval/oldlenp are NULL).

The current strace code complains like so:
_sysctl({{CTL_NET, NET_IPV4, NET_IPV4_LOCAL_PORT_RANGE, 38}, 3, process_vm_readv: Bad address
(nil), 0, 0x7fffe23c3960, 8}) = -1 EACCES (Permission denied)

Since passing NULL for the old values is valid, handle that explicitly.
This also simplifies the code a bit by splitting up the handling of the
new and old args so that we only handle the new args once.

Now the output looks like:
_sysctl({{CTL_NET, NET_IPV4, NET_IPV4_LOCAL_PORT_RANGE, 38}, 3, NULL, 0, 0x7fff8c0c91b0, 8) = -1 EACCES (Permission denied)

* system.c (sys_sysctl): Check if info.oldval is NULL first.  Move the
processing of oldlen/info.newval/info.newlen out so they always get
executed.  Fix the format strings so we use %lu for unsigned long rather
than a mix of %ld and %lu.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
system.c