From bc734845cf9bf634d4c908ebe297bd2126d32d4e Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Wed, 6 Dec 2017 13:34:20 +0000
Subject: [PATCH] ld_libs_load_cache: Don't reopen cache, and fix prefix=""
 case

We were opening the correct ld.so.cache here (in both cases), but then
calling ld_cache_open() which would close the fd we just opened and
open libs->prefix.path instead. In the case where the prefix is set
to "" we would open whatever arbitrary string happened to have been
left in libs->prefix.path last time we used it as scratch space.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 utils/ld-libs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/utils/ld-libs.c b/utils/ld-libs.c
index 6013b6257..6953ebbda 100644
--- a/utils/ld-libs.c
+++ b/utils/ld-libs.c
@@ -1120,13 +1120,12 @@ ld_libs_load_cache (ld_libs *libs, const char *path, int *code, char **message)
 
     if( libs->prefix.len == 0 )
     {
-        libs->ldcache.fd = open( path, O_RDONLY );
+        safe_strncpy( libs->prefix.path, path, sizeof(libs->prefix.path) );
     }
     else
     {
         safe_strncpy( libs->prefix.path + libs->prefix.len,
                       path, PATH_MAX - libs->prefix.len );
-        libs->ldcache.fd = open( libs->prefix.path, O_RDONLY );
     }
 
     rv = ld_cache_open( &libs->ldcache, libs->prefix.path, code, message );
-- 
GitLab