< prev index next >

src/os/linux/vm/os_linux.cpp

Print this page
rev 12741 : 8173848: realpath is unsafe
Summary: Fix occurrences of realpath in hotspot to use safe POSIX.1-2008 form.
Reviewed-by: dsamersoff, dholmes, clanger

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -2316,11 +2316,11 @@
                                          CAST_FROM_FN_PTR(address, os::jvm_path),
                                          dli_fname, sizeof(dli_fname), NULL);
   assert(ret, "cannot locate libjvm");
   char *rp = NULL;
   if (ret && dli_fname[0] != '\0') {
-    rp = realpath(dli_fname, buf);
+    rp = os::Posix::realpath(dli_fname, buf, buflen);
   }
   if (rp == NULL) {
     return;
   }
 

@@ -2350,11 +2350,11 @@
         if (p == NULL) {
           return;
         }
         assert(strstr(p, "/libjvm") == p, "invalid library name");
 
-        rp = realpath(java_home_var, buf);
+        rp = os::Posix::realpath(java_home_var, buf, buflen);
         if (rp == NULL) {
           return;
         }
 
         // determine if this is a legacy image or modules image

@@ -2371,11 +2371,11 @@
           // Use current module name "libjvm.so"
           len = strlen(buf);
           snprintf(buf + len, buflen-len, "/hotspot/libjvm.so");
         } else {
           // Go back to path of .so
-          rp = realpath(dli_fname, buf);
+          rp = os::Posix::realpath(dli_fname, buf, buflen);
           if (rp == NULL) {
             return;
           }
         }
       }
< prev index next >