Skip to contentSkip to conversation

erofs-utils: Fail the image creation when source path is not a directory file.

PATCH New Pratik Shinde 3 participants 4 messages Aug 16, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: Fail the image creation when source path is not a directory file.

In the erofs.mkfs utility, if the source path is not a directory,image creation should not proceed.since root of the filesystem needs to be a directory.

moving the check to main function.

Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>
---
 mkfs/main.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
mkfs/main.c +11 -0
index 93cacca..8fbfced 100644
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 #include <limits.h>
 #include <libgen.h>
+#include <sys/stat.h>
 #include "erofs/config.h"
 #include "erofs/print.h"
 #include "erofs/cache.h"
@@ -187,6 +188,7 @@ int main(int argc, char **argv)
 	struct erofs_buffer_head *sb_bh;
 	struct erofs_inode *root_inode;
 	erofs_nid_t root_nid;
+	struct stat64 st;
 
 	erofs_init_configure();
 	fprintf(stderr, "%s %s\n", basename(argv[0]), cfg.c_version);
@@ -197,6 +199,15 @@ int main(int argc, char **argv)
 			usage();
 		return 1;
 	}
+	err = lstat64(cfg.c_src_path, &st);
+	if (err)
+		return 1;
+	if ((st.st_mode & S_IFMT) != S_IFDIR) {
+		erofs_err("root of the filesystem is not a directory - %s",
+			  cfg.c_src_path);
+		usage();
+		return 1;
+	}
 
 	err = dev_open(cfg.c_img_path);
 	if (err) {
Signature · 1 line
2.9.3
Applied
#1 lore raw

PATCH 1/1 erofs-utils: Fail the image creation when source path is not a directory file.

Quoted 6 lines · Pratik Shinde

In the erofs.mkfs utility, if the source path is not a directory,image creation should not proceed.since root of the filesystem needs to be a directory.

moving the check to main function.

Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>

Applied to dev branch, thank you!

Thanks,
Gao Xiang

Quoted 43 lines
---
 mkfs/main.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
mkfs/main.c +11 -0
index 93cacca..8fbfced 100644
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 #include <limits.h>
 #include <libgen.h>
+#include <sys/stat.h>
 #include "erofs/config.h"
 #include "erofs/print.h"
 #include "erofs/cache.h"
@@ -187,6 +188,7 @@ int main(int argc, char **argv)
 	struct erofs_buffer_head *sb_bh;
 	struct erofs_inode *root_inode;
 	erofs_nid_t root_nid;
+	struct stat64 st;
 
 	erofs_init_configure();
 	fprintf(stderr, "%s %s\n", basename(argv[0]), cfg.c_version);
@@ -197,6 +199,15 @@ int main(int argc, char **argv)
 			usage();
 		return 1;
 	}
+	err = lstat64(cfg.c_src_path, &st);
+	if (err)
+		return 1;
+	if ((st.st_mode & S_IFMT) != S_IFDIR) {
+		erofs_err("root of the filesystem is not a directory - %s",
+			  cfg.c_src_path);
+		usage();
+		return 1;
+	}
 
 	err = dev_open(cfg.c_img_path);
 	if (err) {
Signature · 1 line
2.9.3
#2 lore raw

PATCH 1/1 erofs-utils: Fail the image creation when source path is not a directory file.

In reply to Pratik Shinde

? 2019/8/16 16:56, Pratik Shinde ??:

Quoted 6 lines

In the erofs.mkfs utility, if the source path is not a directory,image creation should not proceed.since root of the filesystem needs to be a directory.

moving the check to main function.

Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>

It looks good.
Reviewed-by Li Guifu <blucerlee at gmail.com>
Thanks

Quoted 41 lines
---
  mkfs/main.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
mkfs/main.c +11 -0
index 93cacca..8fbfced 100644
@@ -12,6 +12,7 @@
  #include <stdlib.h>
  #include <limits.h>
  #include <libgen.h>
+#include <sys/stat.h>
  #include "erofs/config.h"
  #include "erofs/print.h"
  #include "erofs/cache.h"
@@ -187,6 +188,7 @@ int main(int argc, char **argv)
  	struct erofs_buffer_head *sb_bh;
  	struct erofs_inode *root_inode;
  	erofs_nid_t root_nid;
+	struct stat64 st;
 
  	erofs_init_configure();
  	fprintf(stderr, "%s %s\n", basename(argv[0]), cfg.c_version);
@@ -197,6 +199,15 @@ int main(int argc, char **argv)
  			usage();
  		return 1;
  	}
+	err = lstat64(cfg.c_src_path, &st);
+	if (err)
+		return 1;
+	if ((st.st_mode & S_IFMT) != S_IFDIR) {
+		erofs_err("root of the filesystem is not a directory - %s",
+			  cfg.c_src_path);
+		usage();
+		return 1;
+	}
 
  	err = dev_open(cfg.c_img_path);
  	if (err) {
#3 lore raw

PATCH 1/1 erofs-utils: Fail the image creation when source path is not a directory file.

Quoted 11 lines · Li Guifu

?? 2019/8/16 16:56, Pratik Shinde ????:

Quoted 6 lines

In the erofs.mkfs utility, if the source path is not a directory,image creation should not proceed.since root of the filesystem needs to be a directory.

moving the check to main function.

Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>

It looks good.
Reviewed-by Li Guifu <blucerlee at gmail.com>

Fold in the original patch as well :)

Thanks,
Gao Xiang

Quoted 42 lines

Thanks

Quoted 39 lines
---
  mkfs/main.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
mkfs/main.c +11 -0
index 93cacca..8fbfced 100644
@@ -12,6 +12,7 @@
  #include <stdlib.h>
  #include <limits.h>
  #include <libgen.h>
+#include <sys/stat.h>
  #include "erofs/config.h"
  #include "erofs/print.h"
  #include "erofs/cache.h"
@@ -187,6 +188,7 @@ int main(int argc, char **argv)
  	struct erofs_buffer_head *sb_bh;
  	struct erofs_inode *root_inode;
  	erofs_nid_t root_nid;
+	struct stat64 st;
  	erofs_init_configure();
  	fprintf(stderr, "%s %s\n", basename(argv[0]), cfg.c_version);
@@ -197,6 +199,15 @@ int main(int argc, char **argv)
  			usage();
  		return 1;
  	}
+	err = lstat64(cfg.c_src_path, &st);
+	if (err)
+		return 1;
+	if ((st.st_mode & S_IFMT) != S_IFDIR) {
+		erofs_err("root of the filesystem is not a directory - %s",
+			  cfg.c_src_path);
+		usage();
+		return 1;
+	}
  	err = dev_open(cfg.c_img_path);
  	if (err) {