提交 6c3907e8 编写于 作者: W wangjiahui

fix dlsym issue

Signed-off-by: Nwangjiahui <wangjiahui27@huawei.com>
上级 771aa749
......@@ -496,13 +496,58 @@ static void dlopen_ns_randomization_0600(void)
/**
* @tc.name : dlsym_randomization_0300
* @tc.desc : Call the dlsym interface to get symbol address
* @tc.desc : Call the dlsym interface to get symbol address, handle is invalid
* @tc.level : Level2
*/
static void dlsym_randomization_0300(void)
{
void *sym = dlsym(NULL, "test");
EXPECT_FALSE(__FUNCTION__, sym);
void *sym = dlsym((void *)0xFFFF, "invalid_function");
EXPECT_PTREQ(__FUNCTION__, sym, NULL);
}
/**
* @tc.name : dlsym_randomization_0400
* @tc.desc : Call the dlsym interface to get symbol address, handle is setted to RTLD_DEFAULT, and name is valid
* @tc.level : Level1
*/
static void dlsym_randomization_0400(void)
{
void *sym = dlsym(RTLD_DEFAULT, "fopen");
EXPECT_PTRNE(__FUNCTION__, sym, NULL);
}
/**
* @tc.name : dlsym_randomization_0500
* @tc.desc : Call the dlsym interface to get symbol address, handle is setted to RTLD_DEFAULT, and name is invalid
* @tc.level : Level2
*/
static void dlsym_randomization_0500(void)
{
void *sym = dlsym(RTLD_DEFAULT, "invalid_func");
EXPECT_PTREQ(__FUNCTION__, sym, NULL);
}
/**
* @tc.name : dlsym_randomization_0600
* @tc.desc : Call the dlsym interface to get symbol address, handle is setted to RTLD_NEXT, and name is valid
* @tc.level : Level1
*/
static void dlsym_randomization_0600(void)
{
void *sym = dlsym(RTLD_NEXT, "fopen");
EXPECT_PTRNE(__FUNCTION__, sym, NULL);
}
/**
* @tc.name : dlsym_randomization_0700
* @tc.desc : Call the dlsym interface to get symbol address, handle is setted to RTLD_NEXT, and name is invalid
* @tc.level : Level2
*/
static void dlsym_randomization_0700(void)
{
void *sym = dlsym(RTLD_NEXT, "invalid_func");
EXPECT_PTREQ(__FUNCTION__, sym, NULL);
}
/**
......@@ -536,6 +581,10 @@ TEST_FUNC test_cases[] = {
dlopen_ns_randomization_0400,
dlopen_ns_randomization_0600,
dlsym_randomization_0300,
dlsym_randomization_0400,
dlsym_randomization_0500,
dlsym_randomization_0600,
dlsym_randomization_0700,
dlclose_randomization_0100,
};
......
......@@ -2920,12 +2920,16 @@ hidden void *__dlsym(void *restrict p, const char *restrict s, void *restrict ra
void *res;
pthread_rwlock_rdlock(&lock);
#ifdef HANDLE_RANDOMIZATION
struct dso *dso = find_dso_by_handle(p);
if (dso == NULL) {
pthread_rwlock_unlock(&lock);
return 0;
if ((p != RTLD_DEFAULT) && (p != RTLD_NEXT)) {
struct dso *dso = find_dso_by_handle(p);
if (dso == NULL) {
pthread_rwlock_unlock(&lock);
return 0;
}
res = do_dlsym(dso, s, ra);
} else {
res = do_dlsym(p, s, ra);
}
res = do_dlsym(dso, s, ra);
#else
res = do_dlsym(p, s, ra);
#endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册