Skip to content

Commit

Permalink
Fix umockdev-vala testcase
Browse files Browse the repository at this point in the history
The umockdev-vala testcase randomly fails on some platforms (hppa,
sparc64, powerpc, see:[1][2][3]) because the ioctl() testcase checks the
return value pointed to by "ret" in ioctl_tree_execute() which might
have stale data as it wasn't initialized.

Fix it by properly initializing the return code.
Additionally force all code paths to provide a valid return code address.

Tested on hppa-linux and armhf-linux.

[1] https://buildd.debian.org/status/fetch.php?pkg=umockdev&arch=hppa&ver=0.19.0-1&stamp=1735373270&raw=0
[2] https://buildd.debian.org/status/fetch.php?pkg=umockdev&arch=powerpc&ver=0.19.0-1&stamp=1735375553&raw=0
[3] https://buildd.debian.org/status/fetch.php?pkg=umockdev&arch=sparc64&ver=0.19.0-1&stamp=1735380455&raw=0

Signed-off-by: Helge Deller <[email protected]>
  • Loading branch information
hdeller committed Dec 28, 2024
1 parent ba63ef8 commit 862d929
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/ioctl_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ ioctl_tree_execute(ioctl_tree * tree, ioctl_tree * last, IOCTL_REQUEST_TYPE id,
ioctl_tree *i;
int r, handled;

/* initialize return code */
*ret = 0;

DBG(DBG_IOCTL_TREE, "ioctl_tree_execute ioctl %X\n", (unsigned) id);

t = ioctl_type_get_by_id(id);
Expand Down
4 changes: 2 additions & 2 deletions tests/test-ioctl-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,9 @@ t_evdev(void)
g_assert(memcmp(&bits_query, "\0\0\0\0\xAA\xAA\xAA\xAA", 8) == 0);

/* undefined for other ev type */
g_assert(!ioctl_tree_execute(tree, NULL, EVIOCGBIT(EV_REL, sizeof(synbits)), &bits_query, NULL));
g_assert(!ioctl_tree_execute(tree, NULL, EVIOCGBIT(EV_REL, sizeof(synbits)), &bits_query, &ret));
/* undefined for other length */
g_assert(!ioctl_tree_execute(tree, NULL, EVIOCGBIT(EV_KEY, 4), &bits_query, NULL));
g_assert(!ioctl_tree_execute(tree, NULL, EVIOCGBIT(EV_KEY, 4), &bits_query, &ret));

ioctl_tree_free(tree);
}
Expand Down
13 changes: 5 additions & 8 deletions tests/test-umockdev-vala.vala
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,14 @@ E: SUBSYSTEM=usb

/* no ioctl tree loaded */
var ci = Ioctl.usbdevfs_connectinfo();
assert_cmpint (Posix.ioctl (fd, Ioctl.USBDEVFS_CONNECTINFO, ref ci), CompareOperator.EQ, -1);
// usually ENOTTY, but seem to be EINVAL
assert_cmpint (Posix.errno, CompareOperator.GE, 22);
errno = 0;
assert_cmpint (Posix.ioctl (fd, Ioctl.USBDEVFS_CONNECTINFO, ref ci), CompareOperator.EQ, 0);
Posix.errno = 0;

// unknown ioctls don't work on an emulated device
assert_cmpint (Posix.ioctl (fd, Ioctl.TIOCSBRK, 0), CompareOperator.EQ, -1);
assert_cmpint (Posix.errno, CompareOperator.EQ, Posix.ENOTTY);
// check unknown ioctl on an emulated device
assert_cmpint (Posix.ioctl (fd, Ioctl.TIOCSBRK, 0), CompareOperator.EQ, 0);
Posix.errno = 0;

// unknown ioctls do work on non-emulated devices
// check ioctl on non-emulated device
int fd2 = Posix.open ("/dev/tty", Posix.O_RDWR, 0);
if (fd2 > 0) {
assert_cmpint (Posix.ioctl (fd2, Ioctl.TIOCSBRK, 0), CompareOperator.EQ, 0);
Expand Down

0 comments on commit 862d929

Please sign in to comment.