fs: fix path_check_prereq()
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
@@ -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
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
@@ -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
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
Signed-off-by Antony Pavlov <[email protected]>--- fs/fs.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)fs/fs.c +4
-3@@ -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
Quoted 13 lines · Antony Pavlov
This patch makes impossible the situations than
path_check_prereq()can make 'return 0' without changing errno.Signed-off-by Antony Pavlov <[email protected]>--- fs/fs.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)fs/fs.c +0
-0
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
-2errno = -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