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.gere...@wacom.com>
---
 tools/tools-shared.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

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)
        {
-- 
2.15.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to