[beast: 42/47] SFI: get_executable_path: fallback to "/proc/self/exe" if /proc is unmounted



commit c3529b7f8b30b7df03ea137f14b1d67d5dad1299
Author: Tim Janik <timj gnu org>
Date:   Sun Aug 27 20:45:54 2017 +0200

    SFI: get_executable_path: fallback to "/proc/self/exe" if /proc is unmounted
    
    Signed-off-by: Tim Janik <timj gnu org>

 sfi/platform.cc |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/sfi/platform.cc b/sfi/platform.cc
index 4b28b3b..901086c 100644
--- a/sfi/platform.cc
+++ b/sfi/platform.cc
@@ -124,12 +124,17 @@ monotonic_counter ()
 static std::string
 get_executable_path()
 {
-  const ssize_t max_size = 4096;
-  char system_result[max_size + 1] = { 0, };
+  const ssize_t max_size = 4000;
+  char system_result[max_size + 1 + 1] = { 0, };
   ssize_t system_result_size = -1;
 
 #if defined __linux__ || defined __CYGWIN__ || defined __MSYS__
   system_result_size = readlink ("/proc/self/exe", system_result, max_size);
+  if (system_result_size < 0)
+    {
+      strcpy (system_result, "/proc/self/exe");
+      system_result_size = 0;
+    }
 #elif defined __APPLE__
   {
     uint32_t bufsize = max_size;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]