bad_ioctl

bad_ioctl - static void ioctl_badbuf(void) { /* * Since we...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * ioctl */ #include <sys/types.h> #include <sys/ioctl.h> #include <unistd.h> #include <stdio.h> #include <errno.h> #include "config.h" #include "test.h" static void one_ioctl_badbuf(int fd, int code, const char *codename, void *ptr, const char *ptrdesc) { char desc[128]; int rv; snprintf(desc, sizeof(desc), "ioctl %s with %s", codename, ptrdesc); rv = ioctl(fd, code, ptr); report_test(rv, errno, EFAULT, desc); } static void any_ioctl_badbuf(int fd, int code, const char *codename) { one_ioctl_badbuf(fd, code, codename, NULL, "NULL pointer"); one_ioctl_badbuf(fd, code, codename, INVAL_PTR, "invalid pointer"); one_ioctl_badbuf(fd, code, codename, KERN_PTR, "kernel pointer"); } #define IOCTL(fd, sym) any_ioctl_badbuf(fd, sym, #sym)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: static void ioctl_badbuf(void) { /* * Since we don't actually define any ioctls, this code won't * actually run. But if you do define ioctls, turn these tests * on for those that actually use the data buffer argument for * anything. */ /* IOCTL(STDIN_FILENO, TIOCGETA); */ /* suppress gcc warning */ (void)any_ioctl_badbuf; } static void ioctl_badcode(void) { int rv; rv = ioctl(STDIN_FILENO, NONEXIST_IOCTL, NULL); report_test(rv, errno, EIOCTL, &quot;invalid ioctl&quot;); } void test_ioctl(void) { test_ioctl_fd(); /* Since we don't actually define any ioctls, this is not meaningful */ ioctl_badcode(); ioctl_badbuf(); }...
View Full Document

Page1 / 2

bad_ioctl - static void ioctl_badbuf(void) { /* * Since we...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online