[PATCH] avicap32: Fixed a TOCTOU (check vs use) ordering issue (Coverity)
Marcus Meissner
meissner at suse.de
Wed Sep 7 08:29:31 CDT 2011
Hi,
One of the easier fixes. CID 4623
Ciao, Marcus
---
dlls/avicap32/avicap32_main.c | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/dlls/avicap32/avicap32_main.c b/dlls/avicap32/avicap32_main.c
index 3d0b661..5816403 100644
--- a/dlls/avicap32/avicap32_main.c
+++ b/dlls/avicap32/avicap32_main.c
@@ -112,7 +112,13 @@ static BOOL query_video_device(int devnum, char *name, int namesize, char *versi
snprintf(device, sizeof(device), "/dev/video%i", devnum);
- if (stat (device, &st) == -1) {
+ fd = open(device, O_RDWR | O_NONBLOCK);
+ if (fd == -1) {
+ ERR("%s: Failed to open: %s\n", device, strerror(errno));
+ return FALSE;
+ }
+
+ if (fstat (fd, &st) == -1) {
/* This is probably because the device does not exist */
WARN("%s: %s\n", device, strerror(errno));
return FALSE;
@@ -123,12 +129,6 @@ static BOOL query_video_device(int devnum, char *name, int namesize, char *versi
return FALSE;
}
- fd = open(device, O_RDWR | O_NONBLOCK);
- if (fd == -1) {
- ERR("%s: Failed to open: %s\n", device, strerror(errno));
- return FALSE;
- }
-
memset(&caps, 0, sizeof(caps));
if (xioctl(fd, VIDIOC_QUERYCAP, &caps) != -1) {
lstrcpynA(name, (char *)caps.card, namesize);
--
1.7.1
More information about the wine-patches
mailing list