Skip to content
/ server Public

MDEV-39122 Fix my_realpath to treat empty string as current directory#4865

Open
mariadb-andrzejjarzabek wants to merge 2 commits intoMariaDB:10.11from
mariadb-andrzejjarzabek:10.11-MDEV-39122
Open

MDEV-39122 Fix my_realpath to treat empty string as current directory#4865
mariadb-andrzejjarzabek wants to merge 2 commits intoMariaDB:10.11from
mariadb-andrzejjarzabek:10.11-MDEV-39122

Conversation

@mariadb-andrzejjarzabek
Copy link
Copy Markdown

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.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants