From 1b10c3d24628441a1357f6079824d543a12e4e53 Mon Sep 17 00:00:00 2001
From: oddcoder <ahmedsoliman@oddcoder.com>
Date: Mon, 1 Jun 2020 11:41:19 +0200
Subject: [PATCH] Prioterize search path instead of overwriting it.

Current LD_LIBRARY_PATH implementation overwrites the original search
path, which is not the best idea, instead this patch would check
LD_LIBRARY_PATH first and if it didn't find the libraries it is looking
for, then it will search the original search path
---
 src/ld_so/start.rs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/ld_so/start.rs b/src/ld_so/start.rs
index 7b433faa4..92e83a3bd 100644
--- a/src/ld_so/start.rs
+++ b/src/ld_so/start.rs
@@ -138,8 +138,8 @@ pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack, ld_entry: usize) ->
 
     // Some variables that will be overridden by environment and auxiliary vectors
     let library_path = match envs.get("LD_LIBRARY_PATH") {
-        Some(lib_path) => lib_path,
-        None => "/lib",
+        Some(lib_path) => lib_path.to_owned() + ":/lib",
+        None => "/lib".to_owned(),
     };
 
     let path = if is_manual {
@@ -178,7 +178,7 @@ pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack, ld_entry: usize) ->
         }
         pr
     };
-    let mut linker = Linker::new(library_path, false);
+    let mut linker = Linker::new(&library_path, false);
     match linker.load(&path, &path) {
         Ok(()) => (),
         Err(err) => {
-- 
GitLab