From: Gabriel Laskar Date: Wed, 23 Sep 2015 08:11:55 +0000 (+0200) Subject: ioctl: fix ioctl command number decoding in case of conflicts X-Git-Tag: v4.11~162 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9c4fc3404cff4c58b7c9707c85da9661f87131c7;p=strace ioctl: fix ioctl command number decoding in case of conflicts When a command number was decoded through ioctl_decode_command_number(), there was no check for conflicts with other potential ioctls numbers. For example: ioctl(fd, MCE_GET_RECORD_LEN, &i); output: ioctl(3, MIXER_READ(1), 0x7ffddce74a58) = 0 instead of: ioctl(3, MIXER_READ(1) or MCE_GET_RECORD_LEN, 0x7ffee435ce08) = 0 * ioctl.c (SYS_FUNC(ioctl)): Fix ioctl command number decoding in case of conflicts. * tests/ioctl.c (main): Add a case for command number conflicts. Signed-off-by: Gabriel Laskar Signed-off-by: Dmitry V. Levin --- diff --git a/ioctl.c b/ioctl.c index 284828a5..adce9867 100644 --- a/ioctl.c +++ b/ioctl.c @@ -277,15 +277,16 @@ SYS_FUNC(ioctl) if (entering(tcp)) { printfd(tcp, tcp->u_arg[0]); tprints(", "); - if (!ioctl_decode_command_number(tcp)) { - iop = ioctl_lookup(tcp->u_arg[1]); - if (iop) { - tprints(iop->symbol); - while ((iop = ioctl_next_match(iop))) - tprintf(" or %s", iop->symbol); - } else { - ioctl_print_code(tcp->u_arg[1]); - } + ret = ioctl_decode_command_number(tcp); + iop = ioctl_lookup(tcp->u_arg[1]); + if (iop) { + if (ret) + tprints(" or "); + tprints(iop->symbol); + while ((iop = ioctl_next_match(iop))) + tprintf(" or %s", iop->symbol); + } else if (!ret) { + ioctl_print_code(tcp->u_arg[1]); } ret = ioctl_decode(tcp); } else { diff --git a/tests/ioctl.c b/tests/ioctl.c index 7f9b84ce..7882140f 100644 --- a/tests/ioctl.c +++ b/tests/ioctl.c @@ -58,6 +58,10 @@ main(void ) printf("ioctl(-1, EVIOCGBIT(EV_KEY, 8), %p)" " = -1 EBADF (Bad file descriptor)\n", &data); + (void) ioctl(-1, _IOR('M', 13, int), &data); + printf("ioctl(-1, MIXER_READ(13) or OTPSELECT, [MTD_OTP_OFF])" + " = -1 EBADF (Bad file descriptor)\n"); + (void) ioctl(-1, _IOR(0xde, 0xad, data), &data); printf("ioctl(-1, _IOC(_IOC_READ, 0xde, 0xad, 0x08), %p)" " = -1 EBADF (Bad file descriptor)\n", &data);