Skip to contentSkip to conversation

libf2fs: fix to detect stat() failure

PATCH In review Chao Yu 2 participants 7 messages Dec 10, 2018 – Jan 22, 2019 Library code

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 libf2fs: fix to detect stat() failure

stat() can fail due to a lot of reasons, let f2fs_dev_is_umounted() detect such error and handle it correctly.

---
 lib/libf2fs.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
lib/libf2fs.c +8 -1
index c692bf2da635..6a1040feff32 100644
@@ -713,7 +713,14 @@ int f2fs_dev_is_umounted(char *path)
 	st_buf = malloc(sizeof(struct stat));
 	ASSERT(st_buf);
 
-	if (stat(path, st_buf) == 0 && S_ISBLK(st_buf->st_mode)) {
+	ret = stat(path, st_buf);
+	if (ret) {
+		MSG(0, "\tError: stat %s failed!\n", path);
+		free(st_buf);
+		return -1;
+	}
+
+	if (S_ISBLK(st_buf->st_mode)) {
 		int fd = open(path, O_RDONLY | O_EXCL);
 
 		if (fd >= 0) {
Signature · 1 line
2.18.0.rc1
#1 lore raw
Quoted 13 lines · Chao Yu

stat() can fail due to a lot of reasons, let f2fs_dev_is_umounted() detect such error and handle it correctly.

---
 lib/libf2fs.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
lib/libf2fs.c +0 -0
index c692bf2da635..6a1040feff32 100644

lib/libf2fs.c int f2fs_dev_is_umounted(char *path) · line 716

Quoted 5 lines
lib/libf2fs.c +1 -1
@@ -713,7 +713,14 @@ int f2fs_dev_is_umounted(char *path)
 	st_buf = malloc(sizeof(struct stat));
 	ASSERT(st_buf);
 
-	if (stat(path, st_buf) == 0 && S_ISBLK(st_buf->st_mode)) {
+	ret = stat(path, st_buf);

We have to allow creating non-existing image file to build userdata.img. Can we check its errno?

Quoted 12 lines
lib/libf2fs.c +7 -0
+	if (ret) {
+		MSG(0, "\tError: stat %s failed!\n", path);
+		free(st_buf);
+		return -1;
+	}
+
+	if (S_ISBLK(st_buf->st_mode)) {
 		int fd = open(path, O_RDONLY | O_EXCL);
 
 		if (fd >= 0) {
Signature · 1 line
2.18.0.rc1
author
#2 lore raw
Quoted 17 lines · Jaegeuk Kim
Quoted 16 lines · Chao Yu

stat() can fail due to a lot of reasons, let f2fs_dev_is_umounted() detect such error and handle it correctly.

---
 lib/libf2fs.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
lib/libf2fs.c +0 -0
index c692bf2da635..6a1040feff32 100644
@@ -713,7 +713,14 @@ int f2fs_dev_is_umounted(char *path)
 	st_buf = malloc(sizeof(struct stat));
 	ASSERT(st_buf);
 
Quoted 5 lines

lib/libf2fs.c int f2fs_dev_is_umounted(char *path) · line 716

Quoted 2 lines
lib/libf2fs.c +1 -1
-	if (stat(path, st_buf) == 0 && S_ISBLK(st_buf->st_mode)) {
+	ret = stat(path, st_buf);

We have to allow creating non-existing image file to build userdata.img. Can we check its errno?

You mean sload flow? so how about?

if (ret) {
	if (errno == ENOENT && c.func == SLOAD)
		return 0;
	MSG(0, "\tError: stat %s failed!\n", path);
	free(st_buf);
	return -1;
}

Thanks,

Quoted 16 lines
Quoted 13 lines
lib/libf2fs.c +7 -0
+	if (ret) {
+		MSG(0, "\tError: stat %s failed!\n", path);
+		free(st_buf);
+		return -1;
+	}
+
+	if (S_ISBLK(st_buf->st_mode)) {
 		int fd = open(path, O_RDONLY | O_EXCL);
 
 		if (fd >= 0) {
Signature · 1 line
2.18.0.rc1

.

#3 lore raw
Quoted 18 lines · Chao Yu
Quoted 17 lines · Jaegeuk Kim
Quoted 16 lines · Chao Yu

stat() can fail due to a lot of reasons, let f2fs_dev_is_umounted() detect such error and handle it correctly.

---
 lib/libf2fs.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
lib/libf2fs.c +0 -0
index c692bf2da635..6a1040feff32 100644
@@ -713,7 +713,14 @@ int f2fs_dev_is_umounted(char *path)
 	st_buf = malloc(sizeof(struct stat));
 	ASSERT(st_buf);
 
Quoted 7 lines
Quoted 5 lines

lib/libf2fs.c int f2fs_dev_is_umounted(char *path) · line 716

Quoted 2 lines
lib/libf2fs.c +1 -1
-	if (stat(path, st_buf) == 0 && S_ISBLK(st_buf->st_mode)) {
+	ret = stat(path, st_buf);

We have to allow creating non-existing image file to build userdata.img. Can we check its errno?

You mean sload flow? so how about?

mkfs.f2fs on non-existing image file?

Quoted 27 lines
if (ret) {
	if (errno == ENOENT && c.func == SLOAD)
		return 0;
	MSG(0, "\tError: stat %s failed!\n", path);
	free(st_buf);
	return -1;
}

Thanks,

Quoted 16 lines
Quoted 13 lines
lib/libf2fs.c +7 -0
+	if (ret) {
+		MSG(0, "\tError: stat %s failed!\n", path);
+		free(st_buf);
+		return -1;
+	}
+
+	if (S_ISBLK(st_buf->st_mode)) {
 		int fd = open(path, O_RDONLY | O_EXCL);
 
 		if (fd >= 0) {
Signature · 1 line
2.18.0.rc1

.

author
#4 lore raw
Quoted 25 lines · Jaegeuk Kim
Quoted 24 lines · Chao Yu
Quoted 22 lines · Jaegeuk Kim
Quoted 13 lines · Chao Yu

stat() can fail due to a lot of reasons, let f2fs_dev_is_umounted() detect such error and handle it correctly.

---
 lib/libf2fs.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
lib/libf2fs.c +0 -0
index c692bf2da635..6a1040feff32 100644

lib/libf2fs.c int f2fs_dev_is_umounted(char *path) · line 716

Quoted 5 lines
lib/libf2fs.c +1 -1
@@ -713,7 +713,14 @@ int f2fs_dev_is_umounted(char *path)
 	st_buf = malloc(sizeof(struct stat));
 	ASSERT(st_buf);
 
-	if (stat(path, st_buf) == 0 && S_ISBLK(st_buf->st_mode)) {
+	ret = stat(path, st_buf);

We have to allow creating non-existing image file to build userdata.img. Can we check its errno?

Quoted 3 lines
Quoted 1 line

You mean sload flow? so how about?

mkfs.f2fs on non-existing image file?

That's not allowed as e2fsprogs does?

mkfs.ext4 /home/image/img
mke2fs 1.44.4 (18-Aug-2018)
The file /home/image/img does not exist and no size was specified.

Quoted 31 lines
Quoted 10 lines

if (ret) {
	if (errno == ENOENT && c.func == SLOAD)
		return 0;
	MSG(0, "\tError: stat %s failed!\n", path);
	free(st_buf);
	return -1;
}
Quoted 18 lines

Thanks,

Quoted 16 lines
Quoted 13 lines
lib/libf2fs.c +7 -0
+	if (ret) {
+		MSG(0, "\tError: stat %s failed!\n", path);
+		free(st_buf);
+		return -1;
+	}
+
+	if (S_ISBLK(st_buf->st_mode)) {
 		int fd = open(path, O_RDONLY | O_EXCL);
 
 		if (fd >= 0) {
Signature · 1 line
2.18.0.rc1

.

.

#5 lore raw
Quoted 26 lines · Chao Yu
Quoted 25 lines · Jaegeuk Kim
Quoted 24 lines · Chao Yu
Quoted 22 lines · Jaegeuk Kim
Quoted 13 lines · Chao Yu

stat() can fail due to a lot of reasons, let f2fs_dev_is_umounted() detect such error and handle it correctly.

---
 lib/libf2fs.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
lib/libf2fs.c +0 -0
index c692bf2da635..6a1040feff32 100644

lib/libf2fs.c int f2fs_dev_is_umounted(char *path) · line 716

Quoted 5 lines
lib/libf2fs.c +1 -1
@@ -713,7 +713,14 @@ int f2fs_dev_is_umounted(char *path)
 	st_buf = malloc(sizeof(struct stat));
 	ASSERT(st_buf);
 
-	if (stat(path, st_buf) == 0 && S_ISBLK(st_buf->st_mode)) {
+	ret = stat(path, st_buf);

We have to allow creating non-existing image file to build userdata.img. Can we check its errno?

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

You mean sload flow? so how about?

mkfs.f2fs on non-existing image file?

That's not allowed as e2fsprogs does?

I'm not sure it's spec tho, this patch breaks android build which looks like regression. Do we have any issue to fix with this patch?

Quoted 36 lines

mkfs.ext4 /home/image/img
mke2fs 1.44.4 (18-Aug-2018)
The file /home/image/img does not exist and no size was specified.

Quoted 31 lines
Quoted 10 lines

if (ret) {
	if (errno == ENOENT && c.func == SLOAD)
		return 0;
	MSG(0, "\tError: stat %s failed!\n", path);
	free(st_buf);
	return -1;
}
Quoted 18 lines

Thanks,

Quoted 16 lines
Quoted 13 lines
lib/libf2fs.c +7 -0
+	if (ret) {
+		MSG(0, "\tError: stat %s failed!\n", path);
+		free(st_buf);
+		return -1;
+	}
+
+	if (S_ISBLK(st_buf->st_mode)) {
 		int fd = open(path, O_RDONLY | O_EXCL);
 
 		if (fd >= 0) {
Signature · 1 line
2.18.0.rc1

.

.

author
#6 lore raw
Quoted 27 lines · Jaegeuk Kim
Quoted 26 lines · Chao Yu
Quoted 25 lines · Jaegeuk Kim
Quoted 24 lines · Chao Yu
Quoted 22 lines · Jaegeuk Kim
Quoted 13 lines · Chao Yu

stat() can fail due to a lot of reasons, let f2fs_dev_is_umounted() detect such error and handle it correctly.

---
 lib/libf2fs.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
lib/libf2fs.c +0 -0
index c692bf2da635..6a1040feff32 100644

lib/libf2fs.c int f2fs_dev_is_umounted(char *path) · line 716

Quoted 5 lines
lib/libf2fs.c +1 -1
@@ -713,7 +713,14 @@ int f2fs_dev_is_umounted(char *path)
 	st_buf = malloc(sizeof(struct stat));
 	ASSERT(st_buf);
 
-	if (stat(path, st_buf) == 0 && S_ISBLK(st_buf->st_mode)) {
+	ret = stat(path, st_buf);

We have to allow creating non-existing image file to build userdata.img. Can we check its errno?

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

You mean sload flow? so how about?

mkfs.f2fs on non-existing image file?

That's not allowed as e2fsprogs does?

I'm not sure it's spec tho, this patch breaks android build which looks like regression. Do we have any issue to fix with this patch?

No, I think you can remove this patch to make build passed.

Thanks,

Quoted 40 lines
Quoted 37 lines

mkfs.ext4 /home/image/img
mke2fs 1.44.4 (18-Aug-2018)
The file /home/image/img does not exist and no size was specified.

Quoted 31 lines
Quoted 10 lines

if (ret) {
	if (errno == ENOENT && c.func == SLOAD)
		return 0;
	MSG(0, "\tError: stat %s failed!\n", path);
	free(st_buf);
	return -1;
}
Quoted 18 lines

Thanks,

Quoted 16 lines
Quoted 13 lines
lib/libf2fs.c +7 -0
+	if (ret) {
+		MSG(0, "\tError: stat %s failed!\n", path);
+		free(st_buf);
+		return -1;
+	}
+
+	if (S_ISBLK(st_buf->st_mode)) {
 		int fd = open(path, O_RDONLY | O_EXCL);
 
 		if (fd >= 0) {
Signature · 1 line
2.18.0.rc1

.

.

.