< prev index next >

src/os/posix/vm/os_posix.hpp

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

@@ -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.

@@ -94,10 +94,17 @@
 
   // Helper function; describes pthread attributes as short string. String is written
   // to buf with len buflen; buf is returned.
   static char* describe_pthread_attr(char* buf, size_t buflen, const pthread_attr_t* attr);
 
+  // A safe implementation of realpath which will not cause a buffer overflow if the resolved path
+  //   is longer than PATH_MAX.
+  // On success, it will return a pointer to the input buffer.
+  // On error, it will return NULL and set errno. Content of output buffer is undefined.
+  // On truncation error (output buffer too small), it will return NULL and set errno to ENAMETOOLONG.
+  static char* realpath(const char* filename, char* outbuf, size_t outbuflen);
+
 };
 
 /*
  * Crash protection for the watcher thread. Wrap the callback
  * with a sigsetjmp and in case of a SIGSEGV/SIGBUS we siglongjmp
< prev index next >