From 8ab1b6d04ab0335e556c1092dfcb983fbf9db1ac Mon Sep 17 00:00:00 2001 From: Nicholas Chaimov Date: Thu, 23 Oct 2025 22:22:36 +0000 Subject: [PATCH] Fix pathpatch bug when ld.so overwites /__not_exists --- src/client/client/client.c | 11 +++++++++++ src/client/client/client.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/client/client/client.c b/src/client/client/client.c index f9c6f578..a5c6f334 100644 --- a/src/client/client/client.c +++ b/src/client/client/client.c @@ -404,11 +404,13 @@ extern int dlopen_filter(const char *name); static char patch[4096]; static char *last_patch_location = NULL; static int last_patch_len; +static int last_hwcaps_offset; static const char *stat_not_found_prefix = NOT_FOUND_PREFIX "/"; static void pathpatch_old_name(char *filename) { int len; + const char * hwcaps; if (have_stat_patches) return; @@ -419,8 +421,13 @@ static void pathpatch_old_name(char *filename) return; } + hwcaps = strstr(filename, HWCAPS_DIRNAME); + last_hwcaps_offset = (hwcaps != NULL) ? hwcaps - filename : 0; + memcpy(patch, filename, len); + debug_printf2("Patching nonexistent directory name %s\n", filename); memcpy(filename, stat_not_found_prefix, len); + debug_printf2("Patched directory name to %s\n", filename); last_patch_location = filename; last_patch_len = len; } @@ -431,12 +438,16 @@ void restore_pathpatch() return; if (!last_patch_location || !last_patch_len) return; + if (last_hwcaps_offset > 0 && last_hwcaps_offset < last_patch_len) + last_patch_len = last_hwcaps_offset; if (strncmp(last_patch_location, stat_not_found_prefix, last_patch_len) != 0) { last_patch_location = NULL; last_patch_len = 0; return; } + debug_printf2("Restoring patched directory name %s\n", last_patch_location); memcpy(last_patch_location, patch, last_patch_len); + debug_printf2("Restored patched directory name to %s\n", last_patch_location); last_patch_location = NULL; last_patch_len = 0; } diff --git a/src/client/client/client.h b/src/client/client/client.h index ad28b8c7..1e950744 100644 --- a/src/client/client/client.h +++ b/src/client/client/client.h @@ -28,6 +28,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include "spindle_regex.h" #define NOT_FOUND_PREFIX "/__not_exists" +#define HWCAPS_DIRNAME "glibc-hwcaps" extern int use_ldcs; extern int ldcsid;