binfmt: translate symbolic links correctly with realpath
authorJulien Isorce <j.isorce@samsung.com>
Tue, 10 May 2016 12:18:06 +0000 (13:18 +0100)
committerhyokeun <hyokeun.jeon@samsung.com>
Tue, 6 Sep 2016 07:28:53 +0000 (16:28 +0900)
Change-Id: Ic0eeac9de40a8e1082c83b442829ac28f68bff04
Signed-off-by: Julien Isorce <j.isorce@samsung.com>
Signed-off-by: Yury Usishchev <y.usishchev@samsung.com>
linux-user/binfmt.c

index 2a90096..e9e9b65 100644 (file)
@@ -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