blockdev-util: actually specify an access mode on open()
authorLennart Poettering <lennart@poettering.net>
Tue, 23 Mar 2021 13:04:59 +0000 (14:04 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 24 Mar 2021 10:13:34 +0000 (11:13 +0100)
Linux is pretty lenient here, but we should specify the access mode.

(cherry picked from commit 86b86107942e84de4eb22944251694c0ae21b3ee)

src/basic/blockdev-util.c

index 2f3f1aecc8a99c277422940abebabc47d46db13f..676ad9351b25e7c2c7daa3d86a9eca4534bda379 100644 (file)
@@ -68,7 +68,7 @@ int get_block_device(const char *path, dev_t *ret) {
         /* Gets the block device directly backing a file system. If the block device is encrypted, returns
          * the device mapper block device. */
 
-        fd = open(path, O_NOFOLLOW|O_CLOEXEC);
+        fd = open(path, O_RDONLY|O_NOFOLLOW|O_CLOEXEC);
         if (fd < 0)
                 return -errno;