Skip to contentSkip to conversation

fs: fix path_check_prereq()

RFC PATCH In review Antony Pavlov 2 participants 4 messages Oct 18, 2011 – Oct 19, 2011 VFS

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/2 fs: fix path_check_prereq()

This patch makes impossible the situations than path_check_prereq() can make 'return 0' without changing errno.

---
 fs/fs.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
fs/fs.c +4 -3
index 7d65ec8..714fc9b 100644
@@ -293,9 +293,11 @@ static int path_check_prereq(const char *path, unsigned int flags)
 	struct stat s;
 	unsigned int m;
 
+	errno = 0;
+
 	if (stat(path, &s)) {
 		if (flags & S_UB_DOES_NOT_EXIST)
-			return 0;
+			goto out;
 		errno = -ENOENT;
 		goto out;
 	}
@@ -306,7 +308,7 @@ static int path_check_prereq(const char *path, unsigned int flags)
 	}
 
 	if (flags == S_UB_EXISTS)
-		return 0;
+		goto out;
 
 	m = s.st_mode;
 
@@ -325,7 +327,6 @@ static int path_check_prereq(const char *path, unsigned int flags)
 		goto out;
 	}
 
-	errno = 0;
 out:
 	return errno;
 }
Signature · 7 lines
1.7.6.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

RFC PATCH 2/2 fs: fix chdir()

chdir() allocates memory using mormalise_path(). But if path_check_prereq() returns error than memory isn't freed.

---
 fs/fs.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
fs/fs.c +2 -1
index 714fc9b..f42ca36 100644
@@ -347,8 +347,9 @@ int chdir(const char *pathname)
 
 	strcpy(cwd, p);
 
-	free(p);
 out:
+	free(p);
+
 	return errno;
 }
 EXPORT_SYMBOL(chdir);
Signature · 7 lines
1.7.6.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw
In reply to Antony Pavlov
Quoted 2 lines · Antony Pavlov

This patch makes impossible the situations than path_check_prereq() can make 'return 0' without changing errno.

Both applied to master. Thanks for fixing this.

Sascha

Quoted 49 lines
---
 fs/fs.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
fs/fs.c +4 -3
index 7d65ec8..714fc9b 100644
@@ -293,9 +293,11 @@ static int path_check_prereq(const char *path, unsigned int flags)
 	struct stat s;
 	unsigned int m;
 
+	errno = 0;
+
 	if (stat(path, &s)) {
 		if (flags & S_UB_DOES_NOT_EXIST)
-			return 0;
+			goto out;
 		errno = -ENOENT;
 		goto out;
 	}
@@ -306,7 +308,7 @@ static int path_check_prereq(const char *path, unsigned int flags)
 	}
 
 	if (flags == S_UB_EXISTS)
-		return 0;
+		goto out;
 
 	m = s.st_mode;
 
@@ -325,7 +327,6 @@ static int path_check_prereq(const char *path, unsigned int flags)
 		goto out;
 	}
 
-	errno = 0;
 out:
 	return errno;
 }
Signature · 7 lines
1.7.6.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw
In reply to Antony Pavlov
Quoted 13 lines · Antony Pavlov

This patch makes impossible the situations than path_check_prereq() can make 'return 0' without changing errno.

---
 fs/fs.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
fs/fs.c +0 -0
index 7d65ec8..714fc9b 100644

fs/fs.c static int path_check_prereq(const char *path, unsigned int flags) · line 300

Quoted 9 lines
fs/fs.c +3 -1
@@ -293,9 +293,11 @@ static int path_check_prereq(const char *path, unsigned int flags)
 	struct stat s;
 	unsigned int m;
 
+	errno = 0;
+
 	if (stat(path, &s)) {
 		if (flags & S_UB_DOES_NOT_EXIST)
-			return 0;
+			goto out;

Wow. You broke mkdir.

stat() changes errno, so path_check_prereq returns an error value when S_UB_DOES_NOT_EXIST is set and a file does not exist.

Sascha

Quoted 29 lines
fs/fs.c +1 -2
 		errno = -ENOENT;
 		goto out;
 	}
@@ -306,7 +308,7 @@ static int path_check_prereq(const char *path, unsigned int flags)
 	}
 
 	if (flags == S_UB_EXISTS)
-		return 0;
+		goto out;
 
 	m = s.st_mode;
 
@@ -325,7 +327,6 @@ static int path_check_prereq(const char *path, unsigned int flags)
 		goto out;
 	}
 
-	errno = 0;
 out:
 	return errno;
 }
Signature · 7 lines
1.7.6.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox