提交 db1fbbd8 编写于 作者: E Eric Blake

virFileResolveLink: guarantee an absolute path

https://bugzilla.redhat.com/show_bug.cgi?id=608092

* src/util/util.c (virFileResolveLink): Use
canonicalize_file_name, rather than areadlink.
上级 5b26f2d8
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
# include <mntent.h> # include <mntent.h>
#endif #endif
#include "areadlink.h" #include "dirname.h"
#include "virterror_internal.h" #include "virterror_internal.h"
#include "logging.h" #include "logging.h"
#include "event.h" #include "event.h"
...@@ -1178,8 +1178,9 @@ int virFileLinkPointsTo(const char *checkLink, ...@@ -1178,8 +1178,9 @@ int virFileLinkPointsTo(const char *checkLink,
/* /*
* Attempt to resolve a symbolic link, returning the * Attempt to resolve a symbolic link, returning an
* real path * absolute path where only the last component is guaranteed
* not to be a symlink.
* *
* Return 0 if path was not a symbolic, or the link was * Return 0 if path was not a symbolic, or the link was
* resolved. Return -1 with errno set upon error * resolved. Return -1 with errno set upon error
...@@ -1191,6 +1192,10 @@ int virFileResolveLink(const char *linkpath, ...@@ -1191,6 +1192,10 @@ int virFileResolveLink(const char *linkpath,
*resultpath = NULL; *resultpath = NULL;
/* We don't need the full canonicalization of intermediate
* directories, if linkpath is absolute and the basename is
* already a non-symlink. */
if (IS_ABSOLUTE_FILE_NAME(linkpath)) {
if (lstat(linkpath, &st) < 0) if (lstat(linkpath, &st) < 0)
return -1; return -1;
...@@ -1199,8 +1204,9 @@ int virFileResolveLink(const char *linkpath, ...@@ -1199,8 +1204,9 @@ int virFileResolveLink(const char *linkpath,
return -1; return -1;
return 0; return 0;
} }
}
*resultpath = areadlink (linkpath); *resultpath = canonicalize_file_name(linkpath);
return *resultpath == NULL ? -1 : 0; return *resultpath == NULL ? -1 : 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册