Skip to content

Commit

Permalink
Issue #403 -- partial resolution.
Browse files Browse the repository at this point in the history
Substitute dirname of the file being analysed for the special token
$ORIGIN in RPATH.

Change the declaration of action to match the new function prototype
  • Loading branch information
infracaninophile committed Dec 19, 2012
1 parent ba1708b commit bc01543
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
20 changes: 18 additions & 2 deletions libpkg/elfhints.c
Expand Up @@ -244,7 +244,9 @@ scan_dirs_for_shlibs(struct shlib_list *shlib_list, int numdirs,
return 0;
}

int shlib_list_from_rpath(const char *rpath_str)
#define ORIGIN "$ORIGIN"

int shlib_list_from_rpath(const char *rpath_str, const char *dirpath)
{
const char **dirlist;
char *buf;
Expand All @@ -253,18 +255,32 @@ int shlib_list_from_rpath(const char *rpath_str)
int ret;
const char *c;

/* The special token $ORIGIN should be replaced by the
dirpath: adjust buflen calculation to account for this */

numdirs = 1;
for (c = rpath_str; *c != '\0'; c++)
if (*c == ':')
numdirs++;
buflen = numdirs * sizeof(char *) + strlen(rpath_str) + 1;
i = strlen(dirpath) - strlen(ORIGIN);
if (i > 0)
buflen += i;

dirlist = calloc(1, buflen);
if (dirlist == NULL) {
warnx("Out of memory");
return (EPKG_FATAL);
}
buf = (char *)dirlist + numdirs * sizeof(char *);
strcpy(buf, rpath_str);

c = strstr(rpath_str, ORIGIN);
if ( c != NULL ) {
strncpy(buf, rpath_str, c - rpath_str);
strlcat(buf, dirpath, buflen);
strlcat(buf, c + strlen(ORIGIN), buflen);
} else
strlcpy(buf, rpath_str, buflen);

i = 0;
while ((c = strsep(&buf, ":")) != NULL) {
Expand Down
8 changes: 5 additions & 3 deletions libpkg/pkg_elf.c
Expand Up @@ -39,6 +39,7 @@
#include <err.h>
#include <fcntl.h>
#include <gelf.h>
#include <libgen.h>
#ifndef BUNDLED_LIBELF
#include <link.h>
#endif
Expand Down Expand Up @@ -295,8 +296,9 @@ analyse_elf(struct pkg *pkg, const char *fpath,

if (dyn->d_tag != DT_RPATH && dyn->d_tag != DT_RUNPATH)
continue;

shlib_list_from_rpath(elf_strptr(e, sh_link, dyn->d_un.d_val));

shlib_list_from_rpath(elf_strptr(e, sh_link, dyn->d_un.d_val),
dirname(fpath));
break;
}

Expand Down Expand Up @@ -355,7 +357,7 @@ pkg_analyse_files(struct pkgdb *db, struct pkg *pkg)
bool shlibs = false;
bool autodeps = false;
bool developer = false;
int (*action)(void *, struct pkg *, const char *);
int (*action)(void *, struct pkg *, const char *, const char *);

pkg_config_bool(PKG_CONFIG_SHLIBS, &shlibs);
pkg_config_bool(PKG_CONFIG_AUTODEPS, &autodeps);
Expand Down
2 changes: 1 addition & 1 deletion libpkg/private/ldconfig.h
Expand Up @@ -41,7 +41,7 @@ const char *shlib_list_find_by_name(const char *);
void shlib_list_free(void);
void rpath_list_free(void);
int shlib_list_from_elf_hints(const char *);
int shlib_list_from_rpath(const char *);
int shlib_list_from_rpath(const char *, const char *);

void list_elf_hints(const char *);
void update_elf_hints(const char *, int, char **, int);
Expand Down

0 comments on commit bc01543

Please sign in to comment.