提交 8f9577ed 编写于 作者: G George G. Davis 提交者: Shuah Khan

selftests: watchdog: Validate optional file argument

The newly added optional file argument does not validate if the
file is indeed a watchdog, e.g.:

./watchdog-test  -f /dev/zero
Watchdog Ticking Away!

Fix it by confirming that the WDIOC_GETSUPPORT ioctl succeeds.

Fixes: a4864a33 ("selftests: watchdog: Add optional file argument")
Reported-by: NEugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: NGeorge G. Davis <george_davis@mentor.com>
Signed-off-by: NEugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: NShuah Khan <skhan@linuxfoundation.org>
上级 852c8cbf
......@@ -97,6 +97,7 @@ int main(int argc, char *argv[])
int c;
int oneshot = 0;
char *file = "/dev/watchdog";
struct watchdog_info info;
setbuf(stdout, NULL);
......@@ -118,6 +119,16 @@ int main(int argc, char *argv[])
exit(-1);
}
/*
* Validate that `file` is a watchdog device
*/
ret = ioctl(fd, WDIOC_GETSUPPORT, &info);
if (ret) {
printf("WDIOC_GETSUPPORT error '%s'\n", strerror(errno));
close(fd);
exit(ret);
}
optind = 0;
while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册