aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>2020-05-16 01:22:07 +0200
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>2020-05-16 01:29:01 +0200
commit31f31f9cbaee7be806cba38e0ff5431bd44b20a3 (patch)
treea0aa5d4103f37b60d1fa02965007b5904e1e8111
parent50dae3ad750e3ab52d6bfc46b685269367d148ef (diff)
v4l-conf: check file type before opening it
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 <mchehab+huawei@kernel.org>
-rw-r--r--console/v4l-conf.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/console/v4l-conf.c b/console/v4l-conf.c
index c38bf16..c96886b 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;
}

Privacy Policy