summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Isorce <j.isorce@samsung.com>2016-05-10 13:18:06 +0100
committerhyokeun <hyokeun.jeon@samsung.com>2016-09-06 16:28:53 +0900
commitcac56c4878d27ef636188093ba133729519cc22e (patch)
tree3b68df408aec83e529ed6e3fe2d3678451aab6b4
parentaf6d0da3948e5cb82c176c29d40b438e60747f7d (diff)
downloadqemu-cac56c4878d27ef636188093ba133729519cc22e.tar.gz
qemu-cac56c4878d27ef636188093ba133729519cc22e.tar.bz2
qemu-cac56c4878d27ef636188093ba133729519cc22e.zip
binfmt: translate symbolic links correctly with realpath
Change-Id: Ic0eeac9de40a8e1082c83b442829ac28f68bff04 Signed-off-by: Julien Isorce <j.isorce@samsung.com> Signed-off-by: Yury Usishchev <y.usishchev@samsung.com>
-rw-r--r--linux-user/binfmt.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/linux-user/binfmt.c b/linux-user/binfmt.c
index 2a9009621..e9e9b6583 100644
--- a/linux-user/binfmt.c
+++ b/linux-user/binfmt.c
@@ -4,6 +4,7 @@
#include <libgen.h>
#include <string.h>
#include <stdlib.h>
+#include <limits.h>
int main(int argc, char **argv, char **envp)
@@ -29,10 +30,20 @@ int main(int argc, char **argv, char **envp)
/* Now argv[0] is the real qemu binary name */
{
- char *hostbin;
+ int len;
int r;
+ char buf[PATH_MAX];
+ char *hostbin;
+ char *path;
+
+ /* Follow symbolic link if any. */
+ path = realpath(argv[1], buf);
+ if (path == NULL) {
+ /* Error occured, falling back to original argument */
+ path = argv[1];
+ }
- r = asprintf(&hostbin, "/emul/%s", argv[1]);
+ r = asprintf(&hostbin, "/emul/%s", path);
if (!access(hostbin, X_OK) && (r > 0)) {
/*
* We found a host binary replacement for the non-host binary. Let's