dlsym(handle) may search in unrelated libraries

Submitted by Markus Wichmann on Feb. 7, 2019, 8:37 p.m.

Details

Message ID 20190207203732.GH5469@voyager
State New
Series "dlsym(handle) may search in unrelated libraries"
Headers show

Commit Message

Markus Wichmann Feb. 7, 2019, 8:37 p.m.
I accidentally added a crash. Namely exactly here:

> +static void load_deps_runtime(struct dso *p)
> +{
> +	size_t i, ndeps=0, j=0;
> +	struct dso ***deps = &p->deps, **tmp, *dep;
> +	for (; p; p=(*deps)[j++]) {

*deps might be null pointer, which this expression is dereferencing.
Patch is attached.

Ciao,
Markus

Patch hide | download patch | download mbox

From d90e719cccfe09439324b66cd8894d3781b00048 Mon Sep 17 00:00:00 2001
From: Markus Wichmann <nullplan@gmx.net>
Date: Thu, 7 Feb 2019 21:35:17 +0100
Subject: [PATCH 10/10] Fix crash bug from previous commit.

The previous revision would crash if dlopen() was called for a library
with no dependencies.
---
 ldso/dynlink.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index 66e6f18b..85c3db75 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -1136,7 +1136,8 @@  static struct dso *load_library(const char *name, struct dso *needed_by)
 	return p;
 }
 
-static void load_deps_loadtime(struct dso *p) {
+static void load_deps_loadtime(struct dso *p)
+{
 	size_t i;
 	struct dso *dep;
 	p->deps = (struct dso**)&nodeps_dummy;
@@ -1171,6 +1172,7 @@  static void load_deps_runtime(struct dso *p)
 			tmp[ndeps] = 0;
 			*deps = tmp;
 		}
+		if (!*deps) break;
 	}
 	if (!*deps) *deps = (struct dso**)&nodeps_dummy;
 }
-- 
2.20.1