This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/xawtv3.git tree:

Subject: v4l-conf: check file type before opening it
Author:  Mauro Carvalho Chehab <[email protected]>
Date:    Sat May 16 01:22:07 2020 +0200

Let's avoid open the file if it doesn't exist or it is not
a file of the right type.

Signed-off-by: Mauro Carvalho Chehab <[email protected]>

 console/v4l-conf.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

---

http://git.linuxtv.org/cgit.cgi/xawtv3.git/commit/?id=31f31f9cbaee7be806cba38e0ff5431bd44b20a3
diff --git a/console/v4l-conf.c b/console/v4l-conf.c
index c38bf1601efe..c96886b32dbe 100644
--- a/console/v4l-conf.c
+++ b/console/v4l-conf.c
@@ -141,20 +141,23 @@ dev_open(const char *device, int major)
        exit(1);
     }
 
-    /* open & check v4l device */
-    if (-1 == (fd = open(device,O_RDWR))) {
-       fprintf(stderr, "can't open %s: %s\n", device, strerror(errno));
+    /* First check if the device is really a devnode of the right type */
+    if (-1 == stat(device, &stb)) {
+       fprintf(stderr, "stat(%s): %s\n", device, strerror(errno));
        exit(1);
     }
 
-    if (-1 == fstat(fd,&stb)) {
-       fprintf(stderr, "fstat(%s): %s\n", device, strerror(errno));
-       exit(1);
-    }
     if (!S_ISCHR(stb.st_mode) || (major(stb.st_rdev) != major)) {
        fprintf(stderr, "%s: wrong device\n", device);
        exit(1);
     }
+
+    /* Then open it */
+    if (-1 == (fd = open(device,O_RDWR))) {
+       fprintf(stderr, "can't open %s: %s\n", device, strerror(errno));
+       exit(1);
+    }
+
     return fd;
 }
 

_______________________________________________
linuxtv-commits mailing list
[email protected]
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

Reply via email to