< prev index next >

src/os/aix/vm/os_aix.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


1559 
1560 static char saved_jvm_path[MAXPATHLEN] = {0};
1561 
1562 // Find the full path to the current module, libjvm.so.
1563 void os::jvm_path(char *buf, jint buflen) {
1564   // Error checking.
1565   if (buflen < MAXPATHLEN) {
1566     assert(false, "must use a large-enough buffer");
1567     buf[0] = '\0';
1568     return;
1569   }
1570   // Lazy resolve the path to current module.
1571   if (saved_jvm_path[0] != 0) {
1572     strcpy(buf, saved_jvm_path);
1573     return;
1574   }
1575 
1576   Dl_info dlinfo;
1577   int ret = dladdr(CAST_FROM_FN_PTR(void *, os::jvm_path), &dlinfo);
1578   assert(ret != 0, "cannot locate libjvm");
1579   char* rp = realpath((char *)dlinfo.dli_fname, buf);
1580   assert(rp != NULL, "error in realpath(): maybe the 'path' argument is too long?");
1581 
1582   strncpy(saved_jvm_path, buf, sizeof(saved_jvm_path));
1583   saved_jvm_path[sizeof(saved_jvm_path) - 1] = '\0';
1584 }
1585 
1586 void os::print_jni_name_prefix_on(outputStream* st, int args_size) {
1587   // no prefix required, not even "_"
1588 }
1589 
1590 void os::print_jni_name_suffix_on(outputStream* st, int args_size) {
1591   // no suffix required
1592 }
1593 
1594 ////////////////////////////////////////////////////////////////////////////////
1595 // sun.misc.Signal support
1596 
1597 static volatile jint sigint_count = 0;
1598 
1599 static void




1559 
1560 static char saved_jvm_path[MAXPATHLEN] = {0};
1561 
1562 // Find the full path to the current module, libjvm.so.
1563 void os::jvm_path(char *buf, jint buflen) {
1564   // Error checking.
1565   if (buflen < MAXPATHLEN) {
1566     assert(false, "must use a large-enough buffer");
1567     buf[0] = '\0';
1568     return;
1569   }
1570   // Lazy resolve the path to current module.
1571   if (saved_jvm_path[0] != 0) {
1572     strcpy(buf, saved_jvm_path);
1573     return;
1574   }
1575 
1576   Dl_info dlinfo;
1577   int ret = dladdr(CAST_FROM_FN_PTR(void *, os::jvm_path), &dlinfo);
1578   assert(ret != 0, "cannot locate libjvm");
1579   char* rp = os::Posix::realpath((char *)dlinfo.dli_fname, buf, buflen);
1580   assert(rp != NULL, "error in realpath(): maybe the 'path' argument is too long?");
1581 
1582   strncpy(saved_jvm_path, buf, sizeof(saved_jvm_path));
1583   saved_jvm_path[sizeof(saved_jvm_path) - 1] = '\0';
1584 }
1585 
1586 void os::print_jni_name_prefix_on(outputStream* st, int args_size) {
1587   // no prefix required, not even "_"
1588 }
1589 
1590 void os::print_jni_name_suffix_on(outputStream* st, int args_size) {
1591   // no suffix required
1592 }
1593 
1594 ////////////////////////////////////////////////////////////////////////////////
1595 // sun.misc.Signal support
1596 
1597 static volatile jint sigint_count = 0;
1598 
1599 static void


< prev index next >