summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2017-07-06 20:55:41 +0200
committerPali Rohár <pali.rohar@gmail.com>2017-07-06 20:55:41 +0200
commit27a55c3367a3c66b075a2ef622f6aa1a3d19c24b (patch)
tree49a1d6da50ba50414b29edef2c260780962028be
parentcda5dc6116d607cbe72cfe9d799fab890aba7119 (diff)
download0xFFFF-27a55c3367a3c66b075a2ef622f6aa1a3d19c24b.tar.bz2
disk: Choose correct partition in disk_open_dev()
-rw-r--r--src/disk.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/disk.c b/src/disk.c
index 0b6b494..6a75b35 100644
--- a/src/disk.c
+++ b/src/disk.c
@@ -127,9 +127,15 @@ int disk_open_dev(int maj, int min, int partition, int readonly) {
return -1;
}
- memcpy(blkdev+len, "p1", 3);
+ if ( snprintf(blkdev+len, sizeof(blkdev)-len, "p%d", partition) >= (int)(sizeof(blkdev)-len) ) {
+ ERROR("Block device name is too long");
+ return -1;
+ }
if ( stat(blkdev, &st) != 0 || ! S_ISBLK(st.st_mode) ) {
- memcpy(blkdev+len, "1", 2);
+ if ( snprintf(blkdev+len, sizeof(blkdev)-len, "%d", partition) >= (int)(sizeof(blkdev)-len) ) {
+ ERROR("Block device name is too long");
+ return -1;
+ }
if ( stat(blkdev, &st) != 0 || ! S_ISBLK(st.st_mode) ) {
blkdev[len] = 0;
fd = open(blkdev, O_RDONLY);