Skip to content

Commit 9c93ade

Browse files
committed
1 parent 2306234 commit 9c93ade

File tree

6 files changed

+55
-39
lines changed

6 files changed

+55
-39
lines changed

scripts/fuzz/fuzz_standalone.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#endif /* FUZZ_STANDALONE */
1010

1111
const int rtpp_is_lib = 0;
12+
const int rtpp_use_smodules = 1;
1213

1314
#if defined(FUZZ_STANDALONE)
1415
extern int LLVMFuzzerInitialize(int *argc, char ***argv) __attribute__((__weak__));

src/main.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,14 @@
124124
#include "rtpp_memdeb_internal.h"
125125
#endif
126126
#include "rtpp_stacktrace.h"
127+
#include "rtpp_module_if_static.h"
127128
#if defined(LIBRTPPROXY)
128129
#include "librtpproxy.h"
129130
#include "librtpp_main.h"
130-
#include "rtpp_module_if_static.h"
131131
const int rtpp_is_lib __attribute__((weak)) = 1;
132132
#else
133133
const int rtpp_is_lib = 0;
134+
const int rtpp_use_smodules = 0;
134135
#endif
135136

136137
#define PRIO_UNSET (PRIO_MIN - 1)
@@ -359,7 +360,6 @@ init_config(struct rtpp_cfg *cfsp, int argc, const char * const *argv)
359360
cfsp->rrtcp = 1;
360361
cfsp->runcreds->sock_mode = 0;
361362
cfsp->ttl_mode = TTL_UNIFIED;
362-
cfsp->is_lib = rtpp_is_lib;
363363
cfsp->log_level = -1;
364364
cfsp->log_facility = -1;
365365
cfsp->sched_hz = rtpp_get_sched_hz();
@@ -408,13 +408,13 @@ init_config(struct rtpp_cfg *cfsp, int argc, const char * const *argv)
408408
#if ENABLE_MODULE_IF
409409
case LOPT_DSO:
410410
cp = NULL;
411-
#if defined(LIBRTPPROXY)
412-
if (rtpp_static_modules_lookup(optarg) != NULL) {
413-
cp = optarg;
414-
} else {
415-
IC_ERRX(1, "%s: static module is not compiled in", optarg);
411+
if (rtpp_use_smodules) {
412+
if (rtpp_static_modules_lookup(optarg) != NULL) {
413+
cp = optarg;
414+
} else {
415+
IC_ERRX(1, "%s: static module is not compiled in", optarg);
416+
}
416417
}
417-
#endif
418418
if (cp == NULL)
419419
cp = realpath(optarg, mpath);
420420
if (cp == NULL) {

src/rtpp_cfg.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ struct rtpp_cfg {
156156
struct rtpp_proc_servers *proc_servers;
157157
struct rtpp_genuid *guid;
158158

159-
int is_lib;
160159
#if ENABLE_MODULE_IF
161160
struct rtpp_modman *modules_cf;
162161
#else

src/rtpp_module_if.c

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -199,45 +199,57 @@ acct_rtcp_enqueue(const struct pkt_proc_ctx *pktx)
199199
return (PPROC_ACT_TEE);
200200
}
201201

202+
static const struct rtpp_minfo *
203+
rtpp_modules_lookup(struct rtpp_module_if *self, const char *mpath, struct rtpp_log *log)
204+
{
205+
const struct rtpp_minfo *mip = NULL;
206+
207+
const char *derr;
208+
int dlflags = RTLD_NOW | (is_gcov_on() ? RTLD_NODELETE : 0);
209+
void *dmp = dlopen(mpath, dlflags);
210+
if (dmp == NULL) {
211+
derr = dlerror();
212+
if (strstr(derr, mpath) == NULL) {
213+
RTPP_LOG(log, RTPP_LOG_ERR, "can't dlopen(%s): %s", mpath, derr);
214+
} else {
215+
RTPP_LOG(log, RTPP_LOG_ERR, "can't dlopen() module: %s", derr);
216+
}
217+
goto e1;
218+
}
219+
RTPP_OBJ_DTOR_ATTACH_s(self, dlclose, dmp);
220+
mip = dlsym(dmp, "rtpp_module");
221+
if (mip == NULL) {
222+
derr = dlerror();
223+
if (strstr(derr, mpath) == NULL) {
224+
RTPP_LOG(log, RTPP_LOG_ERR, "can't find 'rtpp_module' symbol in the %s"
225+
": %s", mpath, derr);
226+
} else {
227+
RTPP_LOG(log, RTPP_LOG_ERR, "can't find 'rtpp_module' symbol: %s",
228+
derr);
229+
}
230+
goto e1;
231+
}
232+
return (mip);
233+
e1:
234+
return (NULL);
235+
}
236+
237+
202238
static int
203239
rtpp_mif_load(struct rtpp_module_if *self, const struct rtpp_cfg *cfsp, struct rtpp_log *log)
204240
{
205241
struct rtpp_module_if_priv *pvt;
206-
const char *derr;
207242
const struct rtpp_minfo *mip = NULL;
208243

209244
PUB2PVT(self, pvt);
210-
if (rtpp_is_lib) {
245+
246+
if (rtpp_use_smodules) {
211247
mip = rtpp_static_modules_lookup(pvt->mpath);
212-
if (mip == NULL)
213-
goto e1;
214-
}
215-
if (mip == NULL) {
216-
int dlflags = RTLD_NOW | (is_gcov_on() ? RTLD_NODELETE : 0);
217-
void *dmp = dlopen(pvt->mpath, dlflags);
218-
if (dmp == NULL) {
219-
derr = dlerror();
220-
if (strstr(derr, pvt->mpath) == NULL) {
221-
RTPP_LOG(log, RTPP_LOG_ERR, "can't dlopen(%s): %s", pvt->mpath, derr);
222-
} else {
223-
RTPP_LOG(log, RTPP_LOG_ERR, "can't dlopen() module: %s", derr);
224-
}
225-
goto e1;
226-
}
227-
RTPP_OBJ_DTOR_ATTACH_s(&(pvt->pub), dlclose, dmp);
228-
mip = dlsym(dmp, "rtpp_module");
229-
if (mip == NULL) {
230-
derr = dlerror();
231-
if (strstr(derr, pvt->mpath) == NULL) {
232-
RTPP_LOG(log, RTPP_LOG_ERR, "can't find 'rtpp_module' symbol in the %s"
233-
": %s", pvt->mpath, derr);
234-
} else {
235-
RTPP_LOG(log, RTPP_LOG_ERR, "can't find 'rtpp_module' symbol: %s",
236-
derr);
237-
}
238-
goto e1;
239-
}
248+
} else {
249+
mip = rtpp_modules_lookup(self, pvt->mpath, log);
240250
}
251+
if (mip == NULL)
252+
goto e1;
241253

242254
if (!MI_VER_CHCK(mip) || mip->fn == NULL) {
243255
RTPP_LOG(log, RTPP_LOG_ERR, "incompatible API version in the %s, "

src/rtpp_module_if_static.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "rtpp_linker_set.h"
3131
#include "rtpp_module_if_static.h"
3232

33+
const int rtpp_use_smodules __attribute__((weak)) = 1;
34+
3335
SET_DECLARE(rtpp_modules, const struct rtpp_minfo);
3436

3537
const struct rtpp_minfo *

src/rtpp_module_if_static.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@
2626

2727
#pragma once
2828

29+
extern const int rtpp_use_smodules;
30+
2931
const struct rtpp_minfo *rtpp_static_modules_lookup(const char *);

0 commit comments

Comments
 (0)