From 91675b5bc8d6ba1d4610d369ff4ab34eecde2b26 Mon Sep 17 00:00:00 2001
From: jD91mZM2 <me@krake.one>
Date: Sun, 7 Oct 2018 15:12:41 +0200
Subject: [PATCH] realpath on redox: don't forget the nul terminator

---
 src/platform/linux/mod.rs |  4 ++--
 src/platform/redox/mod.rs | 13 ++++++++++++-
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs
index a194e041..7d2df45b 100644
--- a/src/platform/linux/mod.rs
+++ b/src/platform/linux/mod.rs
@@ -324,8 +324,8 @@ impl Pal for Sys {
         write!(proc_path, "{}", *file).unwrap();
         proc_path.push(0);
 
-        let len = out.len() - 1;
-        let read = readlink(CStr::from_bytes_with_nul(&proc_path).unwrap(), &mut out[..len]);
+        let len = out.len();
+        let read = readlink(CStr::from_bytes_with_nul(&proc_path).unwrap(), &mut out[..len-1]);
         if read < 0 {
             return -1;
         }
diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs
index 9767de08..fef69bff 100644
--- a/src/platform/redox/mod.rs
+++ b/src/platform/redox/mod.rs
@@ -622,7 +622,18 @@ impl Pal for Sys {
             Err(_) => return -1
         };
 
-        e(syscall::fpath(*file as usize, out)) as c_int
+        if out.is_empty() {
+            return 0;
+        }
+
+        let len = out.len();
+        let read = e(syscall::fpath(*file as usize, &mut out[..len-1]));
+        if (read as c_int) < 0 {
+            return -1;
+        }
+        out[read as usize] = 0;
+
+        0
     }
 
     fn rename(oldpath: &CStr, newpath: &CStr) -> c_int {
-- 
GitLab