MDEV-39122 Fix my_realpath to treat empty string as current directory#4865
Open
mariadb-andrzejjarzabek wants to merge 2 commits intoMariaDB:10.11from
Open
MDEV-39122 Fix my_realpath to treat empty string as current directory#4865mariadb-andrzejjarzabek wants to merge 2 commits intoMariaDB:10.11from
mariadb-andrzejjarzabek wants to merge 2 commits intoMariaDB:10.11from
Conversation
|
|
The function my_realpath by default tries to pass its argument to the system function realpath, and attempts a fallback which doesn't resolve symlinks. The problem is my_realpath may be used to resolve symlinks in paths to files and directories that may not exist, for example the function error_if_data_home_dir() may be used to prevent creation of files in the server's data directory. For this reason it attempts to check the provided path's enclosing directory. The problem is when the provided path is a plain file name - interpreted as relative path to the file in the current directory. In this case the "enclosing directory" path will be an empty string, which to realpath() is an incorrect path - it fails with a "file not found" error. The fallback in my_realpath does resolve the empty string to the path of the current directory, but without resolving symlinks. The fix is to change specification and implementation of my_realpath to explicitly treat an empty string argument as a path to the current directory, fixing not only error_if_data_home_dir() but also potential other similar usage patterns.
491265c to
b28c101
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The function my_realpath by default tries to pass its argument to the system function realpath, and attempts a fallback which doesn't resolve symlinks. The problem is my_realpath may be used to resolve symlinks in paths to files and directories that may not exist, for example the function error_if_data_home_dir() may be used to prevent creation of files in the server's data directory. For this reason it attempts to check the provided path's enclosing directory. The problem is when the provided path is a plain file name - interpreted as relative path to the file in the current directory. In this case the "enclosing directory" path will be an empty string, which to realpath() is an incorrect path - it fails with a "file not found" error. The fallback in my_realpath does resolve the empty string to the path of the current directory, but without resolving symlinks.
The fix is to change specification and implementation of my_realpath to explicitly treat an empty string argument as a path to the current directory, fixing not only error_if_data_home_dir() but also potential other similar usage patterns.