From c940cb2cb602f924c5a435c671dabc2ddff14f5e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 4 Nov 2011 08:39:02 +0530 Subject: [PATCH] calibre-mount-helper: Refuse to mount non block devices --- src/calibre/devices/linux_mount_helper.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/calibre/devices/linux_mount_helper.c b/src/calibre/devices/linux_mount_helper.c index 7829d43fad..2ab83f3c3c 100644 --- a/src/calibre/devices/linux_mount_helper.c +++ b/src/calibre/devices/linux_mount_helper.c @@ -236,8 +236,9 @@ int cleanup(const char *dev, const char *mp) { return cleanup_mount_point(mp); } -void check_dev(const char*dev) { +void check_dev(const char *dev) { char buffer[PATH_MAX+1]; + struct stat file_info; if (dev == NULL || strlen(dev) < strlen(DEV)) { fprintf(stderr, "Invalid arguments\n"); @@ -253,6 +254,16 @@ void check_dev(const char*dev) { fprintf(stderr, "Trying to operate on a dev node not under /dev\n"); exit(EXIT_FAILURE); } + + if (stat(dev, &file_info) != 0) { + fprintf(stderr, "stat call on dev node failed\n"); + exit(EXIT_FAILURE); + } + + if (!S_ISBLK(file_info.st_mode)) { + fprintf(stderr, "dev node is not a block device\n"); + exit(EXIT_FAILURE); + } } int main(int argc, char** argv)