mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-04-18 06:46:28 -04:00
only dlopen from the defined search paths
Don't accept absolute library paths and skip the ../ in paths to avoid opening arbitrary libraries from unexpected places.
This commit is contained in:
parent
ad0bab69a1
commit
8fd7982087
4 changed files with 51 additions and 50 deletions
|
|
@ -158,34 +158,32 @@ static inline int weakjack_load_by_path(struct weakjack *jack, const char *path)
|
|||
static inline int weakjack_load(struct weakjack *jack, const char *lib)
|
||||
{
|
||||
int res = -ENOENT;
|
||||
const char *search_dirs, *p, *state = NULL;
|
||||
char path[PATH_MAX];
|
||||
size_t len;
|
||||
|
||||
if (lib[0] != '/') {
|
||||
const char *search_dirs, *p, *state = NULL;
|
||||
char path[PATH_MAX];
|
||||
size_t len;
|
||||
while ((p = strstr(lib, "../")) != NULL)
|
||||
lib = p + 3;
|
||||
|
||||
search_dirs = getenv("LIBJACK_PATH");
|
||||
if (!search_dirs)
|
||||
search_dirs = PREFIX "/lib64/:" PREFIX "/lib/:"
|
||||
"/usr/lib64/:/usr/lib/:" LIBDIR;
|
||||
search_dirs = getenv("LIBJACK_PATH");
|
||||
if (!search_dirs)
|
||||
search_dirs = PREFIX "/lib64/:" PREFIX "/lib/:"
|
||||
"/usr/lib64/:/usr/lib/:" LIBDIR;
|
||||
|
||||
while ((p = pw_split_walk(search_dirs, ":", &len, &state))) {
|
||||
int pathlen;
|
||||
while ((p = pw_split_walk(search_dirs, ":", &len, &state))) {
|
||||
int pathlen;
|
||||
|
||||
if (len >= sizeof(path)) {
|
||||
res = -ENAMETOOLONG;
|
||||
continue;
|
||||
}
|
||||
pathlen = snprintf(path, sizeof(path), "%.*s/%s", (int) len, p, lib);
|
||||
if (pathlen < 0 || (size_t) pathlen >= sizeof(path)) {
|
||||
res = -ENAMETOOLONG;
|
||||
continue;
|
||||
}
|
||||
if ((res = weakjack_load_by_path(jack, path)) == 0)
|
||||
break;
|
||||
if (len >= sizeof(path)) {
|
||||
res = -ENAMETOOLONG;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
res = weakjack_load_by_path(jack, lib);
|
||||
pathlen = snprintf(path, sizeof(path), "%.*s/%s", (int) len, p, lib);
|
||||
if (pathlen < 0 || (size_t) pathlen >= sizeof(path)) {
|
||||
res = -ENAMETOOLONG;
|
||||
continue;
|
||||
}
|
||||
if ((res = weakjack_load_by_path(jack, path)) == 0)
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue