summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Gerecke <killertofu@gmail.com>2017-11-28 15:07:26 -0800
committerJason Gerecke <killertofu@gmail.com>2017-12-19 09:41:04 -0800
commit28c1d6d9ed0624b7a3fb007f764e05e0e2906e24 (patch)
treece6950ca5f9035808b06a63db352d1031fa13b66
parent4a24a94d3ae2396b297a6dab4b350bd5da26d44e (diff)
downloadxf86-input-wacom-28c1d6d9ed0624b7a3fb007f764e05e0e2906e24.tar.gz
tools: Prevent use of invalid (negative) fd
If something goes wrong when a tool attempts to open a device, we print an error but then continue on as though nothing happended and provide the fd to both the ioctl() and close() functions. This commit ensures we don't actually try to use the fd. Coverity-id: 208168 Fixes: 3546d8ab1b ("tools: add isdv4-serial-debugger test program.") Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--tools/tools-shared.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/tools/tools-shared.c b/tools/tools-shared.c
index 3485ac2..c55e8ca 100644
--- a/tools/tools-shared.c
+++ b/tools/tools-shared.c
@@ -55,8 +55,10 @@ int open_device(const char *path)
TRACE("Opening device '%s'.\n", path);
fd = open(path, O_RDWR | O_NOCTTY);
- if (fd < 1)
+ if (fd < 1) {
perror("Failed to open device file");
+ goto out;
+ }
if (ioctl(fd, TIOCGSERIAL, &ser) == -1)
{