< prev index next >

src/os/posix/vm/os_posix.hpp

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 /*
   2  * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


  79   static void print_signal_set_short(outputStream* st, const sigset_t* set);
  80 
  81   // unblocks the signal masks for current thread
  82   static int unblock_thread_signal_mask(const sigset_t *set);
  83 
  84   // Writes a one-line description of a combination of sigaction.sa_flags
  85   // into a user provided buffer. Returns that buffer.
  86   static const char* describe_sa_flags(int flags, char* buffer, size_t size);
  87 
  88   // Prints a one-line description of a combination of sigaction.sa_flags.
  89   static void print_sa_flags(outputStream* st, int flags);
  90 
  91   static address ucontext_get_pc(const ucontext_t* ctx);
  92   // Set PC into context. Needed for continuation after signal.
  93   static void ucontext_set_pc(ucontext_t* ctx, address pc);
  94 
  95   // Helper function; describes pthread attributes as short string. String is written
  96   // to buf with len buflen; buf is returned.
  97   static char* describe_pthread_attr(char* buf, size_t buflen, const pthread_attr_t* attr);
  98 







  99 };
 100 
 101 /*
 102  * Crash protection for the watcher thread. Wrap the callback
 103  * with a sigsetjmp and in case of a SIGSEGV/SIGBUS we siglongjmp
 104  * back.
 105  * To be able to use this - don't take locks, don't rely on destructors,
 106  * don't make OS library calls, don't allocate memory, don't print,
 107  * don't call code that could leave the heap / memory in an inconsistent state,
 108  * or anything else where we are not in control if we suddenly jump out.
 109  */
 110 class WatcherThreadCrashProtection : public StackObj {
 111 public:
 112   WatcherThreadCrashProtection();
 113   bool call(os::CrashProtectionCallback& cb);
 114 
 115   static void check_crash_protection(int signal, Thread* thread);
 116 private:
 117   void restore();
 118   sigjmp_buf _jmpbuf;
   1 /*
   2  * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


  79   static void print_signal_set_short(outputStream* st, const sigset_t* set);
  80 
  81   // unblocks the signal masks for current thread
  82   static int unblock_thread_signal_mask(const sigset_t *set);
  83 
  84   // Writes a one-line description of a combination of sigaction.sa_flags
  85   // into a user provided buffer. Returns that buffer.
  86   static const char* describe_sa_flags(int flags, char* buffer, size_t size);
  87 
  88   // Prints a one-line description of a combination of sigaction.sa_flags.
  89   static void print_sa_flags(outputStream* st, int flags);
  90 
  91   static address ucontext_get_pc(const ucontext_t* ctx);
  92   // Set PC into context. Needed for continuation after signal.
  93   static void ucontext_set_pc(ucontext_t* ctx, address pc);
  94 
  95   // Helper function; describes pthread attributes as short string. String is written
  96   // to buf with len buflen; buf is returned.
  97   static char* describe_pthread_attr(char* buf, size_t buflen, const pthread_attr_t* attr);
  98 
  99   // A safe implementation of realpath which will not cause a buffer overflow if the resolved path
 100   //   is longer than PATH_MAX.
 101   // On success, returns 'outbuf', which now contains the path.
 102   // On error, it will return NULL and set errno. The content of 'outbuf' is undefined.
 103   // On truncation error ( 'outbuf' too small), it will return NULL and set errno to ENAMETOOLONG.
 104   static char* realpath(const char* filename, char* outbuf, size_t outbuflen);
 105 
 106 };
 107 
 108 /*
 109  * Crash protection for the watcher thread. Wrap the callback
 110  * with a sigsetjmp and in case of a SIGSEGV/SIGBUS we siglongjmp
 111  * back.
 112  * To be able to use this - don't take locks, don't rely on destructors,
 113  * don't make OS library calls, don't allocate memory, don't print,
 114  * don't call code that could leave the heap / memory in an inconsistent state,
 115  * or anything else where we are not in control if we suddenly jump out.
 116  */
 117 class WatcherThreadCrashProtection : public StackObj {
 118 public:
 119   WatcherThreadCrashProtection();
 120   bool call(os::CrashProtectionCallback& cb);
 121 
 122   static void check_crash_protection(int signal, Thread* thread);
 123 private:
 124   void restore();
 125   sigjmp_buf _jmpbuf;
< prev index next >