瀏覽代碼

core: test if a module exports functions before converting to core struct

- reported by Juha Heinanen
Daniel-Constantin Mierla 7 年之前
父節點
當前提交
feaafdb268
共有 1 個文件被更改,包括 4 次插入2 次删除
  1. 4 2
      src/core/sr_module.c

+ 4 - 2
src/core/sr_module.c

@@ -208,7 +208,7 @@ static int register_module(module_exports_t* e, char* path, void* handle)
 	int ret, i;
 	struct sr_module* mod;
 	char defmod[64];
-	int n;
+	int n = 0;
 
 	ret=-1;
 
@@ -227,7 +227,9 @@ static int register_module(module_exports_t* e, char* path, void* handle)
 
 	mod->exports.dlflags = e->dlflags;
 
-	for (n=0; e->cmds[n].name; n++);
+	if(e->cmds) {
+		for (n=0; e->cmds[n].name; n++);
+	}
 	mod->exports.cmds = pkg_malloc(sizeof(ksr_cmd_export_t)*(n+1));
 	memset(mod->exports.cmds, 0, sizeof(ksr_cmd_export_t)*(n+1));
 	for (i=0; i < n; i++) {