libaacs | branch: master | npzacs <npz...@gmail.com> | Mon Sep 25 12:59:06 2017 +0300| [88cb927b8fb517e0535c09676bd39db3b8317afb] | committer: npzacs
Fix TOCTOU > http://git.videolan.org/gitweb.cgi/libaacs.git/?a=commit;h=88cb927b8fb517e0535c09676bd39db3b8317afb --- src/file/mmc_device_linux.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/file/mmc_device_linux.c b/src/file/mmc_device_linux.c index 1224956..9417e8f 100644 --- a/src/file/mmc_device_linux.c +++ b/src/file/mmc_device_linux.c @@ -114,22 +114,20 @@ static int _open_block_device(const char *path) struct stat st; int fd; - if (stat(path, &st)) { - BD_DEBUG(DBG_MMC | DBG_CRIT, "stat(%s) failed\n", path); - return -1; - } - - if (!S_ISBLK(st.st_mode)) { + fd = open(path, O_RDONLY | O_NONBLOCK); + if (fd < 0) { + BD_DEBUG(DBG_MMC | DBG_CRIT, "Error opening %s\n", path); return -1; } - BD_DEBUG(DBG_MMC, "Opening block device %s\n", path); - fd = open(path, O_RDONLY | O_NONBLOCK); - if (fd < 0) { - BD_DEBUG(DBG_MMC | DBG_CRIT, "Error opening block device %s\n", path); + if (!fstat(fd, &st) && S_ISBLK(st.st_mode)) { + BD_DEBUG(DBG_MMC, "Opened block device %s\n", path); + return fd; } - return fd; + BD_DEBUG(DBG_MMC, "%s is not a block device\n", path); + close(fd); + return -1; } MMCDEV *device_open(const char *path) _______________________________________________ libaacs-devel mailing list libaacs-devel@videolan.org https://mailman.videolan.org/listinfo/libaacs-devel