diff options
Diffstat (limited to 'safepath.c')
-rw-r--r-- | safepath.c | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -181,7 +181,7 @@ int safepath_check(const char *name) const char *start = (*name == '/') ? "/" : "."; size_t pos = (*name == '/') ? 1 : 0; char *copy; - int ret = SAFEPATH_OK, count = 0; + int ret = SAFEPATH_OK, count = 0, root_checked = (*name == '/'); /* empty name is invalid */ if (*name == 0) { @@ -265,6 +265,17 @@ int safepath_check(const char *name) * Either way it's string grafting. */ if (link[0] == '/') { + /* We have to check the root directory, if we have + * not done so before. + */ + if (!root_checked) { + if (stat("/", &st) < 0) { + ret = safepath_err(errno); + goto free_out; + } + root_checked = 1; + } + /* If savechar is zero, we are working with the last component. * If the last component is an absolute symlink, we just replace * the path with the target, and iterate. Otherwise, we must |