Skip to content

Commit

Permalink
Fix LD_PRELOAD w/o rtld case
Browse files Browse the repository at this point in the history
2016-03-22   Mark Hatle <[email protected]>
        * src/gather.c, src/get.c: Fix LD_PRELOAD

Signed-off-by: Mark Hatle <[email protected]>
  • Loading branch information
Mark Hatle committed Mar 22, 2016
1 parent 8f55afd commit 5cb7a3e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2016-03-22 Mark Hatle <[email protected]>
* src/gather.c, src/get.c: Fix LD_PRELOAD

2016-03-18 Donn Seeley <[email protected]>
* src/rtld/rtld.c: rewrite build_local_scope to ensure breadth-first
processing
Expand Down
18 changes: 14 additions & 4 deletions src/gather.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,20 @@ gather_deps (DSO *dso, struct prelink_entry *ent)
}
argv[i++] = ent_filename;
argv[i] = NULL;
envp[0] = "LD_TRACE_LOADED_OBJECTS=1";
envp[1] = "LD_TRACE_PRELINKING=1";
envp[2] = "LD_WARN=";
envp[3] = NULL;

j = 0;
if(etype == ET_EXEC && ld_preload)
{
p = alloca (sizeof "LD_PRELOAD=" + strlen (ld_preload) + 1);
strcpy (stpcpy (p, "LD_PRELOAD="), ld_preload);
envp[j++] = p;
}

envp[j++] = "LD_TRACE_LOADED_OBJECTS=1";
envp[j++] = "LD_TRACE_PRELINKING=1";
envp[j++] = "LD_WARN=";
envp[j] = NULL;

f = execve_open (dl, (char * const *)argv, (char * const *)envp);
}
else
Expand Down
21 changes: 15 additions & 6 deletions src/get.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ prelink_get_relocations (struct prelink_info *info)
FILE *f;
DSO *dso = info->dso;
const char *argv[8];
const char *envp[4];
int i, ret, status;
const char *envp[5];
int i, j, ret, status;
char *p;
const char *dl = dynamic_linker ?: dso->arch->dynamic_linker;
const char *ent_filename;
Expand Down Expand Up @@ -693,12 +693,21 @@ prelink_get_relocations (struct prelink_info *info)
}
argv[i++] = ent_filename;
argv[i] = NULL;
envp[0] = "LD_TRACE_LOADED_OBJECTS=1";
envp[1] = "LD_BIND_NOW=1";

j = 0;
if(etype == ET_EXEC && ld_preload)
{
p = alloca (sizeof "LD_PRELOAD=" + strlen (ld_preload));
strcpy (stpcpy (p, "LD_PRELOAD="), ld_preload);
envp[j++] = p;
}
envp[j++] = "LD_TRACE_LOADED_OBJECTS=1";
envp[j++] = "LD_BIND_NOW=1";
p = alloca (sizeof "LD_TRACE_PRELINKING=" + strlen (info->ent->filename));
strcpy (stpcpy (p, "LD_TRACE_PRELINKING="), info->ent->filename);
envp[2] = p;
envp[3] = NULL;
envp[j++] = p;
envp[j] = NULL;

ret = 2;
f = execve_open (dl, (char * const *)argv, (char * const *)envp);
}
Expand Down

0 comments on commit 5cb7a3e

Please sign in to comment.