diff options
| author | cbdev <cb@cbcdn.com> | 2019-06-01 21:27:52 +0200 |
|---|---|---|
| committer | cbdev <cb@cbcdn.com> | 2019-06-01 21:27:52 +0200 |
| commit | b9297647c68c963a977e2c18f421211e24f9e85a (patch) | |
| tree | 173d0533f7c76665dea9956ed4da4f3228e01dc9 /plugin.c | |
| parent | 92a291b5fae32caba2212192bc94b8ef568c362d (diff) | |
| download | websocksy-b9297647c68c963a977e2c18f421211e24f9e85a.tar.gz websocksy-b9297647c68c963a977e2c18f421211e24f9e85a.tar.bz2 websocksy-b9297647c68c963a977e2c18f421211e24f9e85a.zip | |
Implement file backend
Diffstat (limited to 'plugin.c')
| -rw-r--r-- | plugin.c | 15 |
1 files changed, 4 insertions, 11 deletions
@@ -43,20 +43,12 @@ int plugin_framing_load(char* path){ DIR* directory = opendir(path); struct dirent* file = NULL; char plugin_path[MAX_PLUGIN_PATH] = ""; - size_t path_len; - if(strlen(path) >= sizeof(plugin_path) - 20){ + if(strlen(path) >= sizeof(plugin_path) - 20 || strlen(path) == 0){ fprintf(stderr, "Plugin path length exceeds limit\n"); return 1; } - strncpy(plugin_path, path, sizeof(plugin_path) - 2); - if(path[strlen(path) - 1] != '/'){ - plugin_path[strlen(path)] = '/'; - plugin_path[strlen(path) + 1] = 0; - } - path_len = strlen(plugin_path); - if(!directory){ fprintf(stderr, "Failed to open directory %s: %s\n", path, strerror(errno)); return 0; @@ -71,7 +63,8 @@ int plugin_framing_load(char* path){ if(strlen(file->d_name) < 4 || strcmp(file->d_name + strlen(file->d_name) - 3, ".so")){ continue; } - strncpy(plugin_path + path_len, file->d_name, sizeof(plugin_path) - path_len - 2); + + snprintf(plugin_path, sizeof(plugin_path), "%s%s%s", path, (path[strlen(path) - 1] == '/') ? "" : "/", file->d_name); if(!plugin_attach(plugin_path)){ return 1; } @@ -85,7 +78,7 @@ int plugin_backend_load(char* path, char* backend_requested, ws_backend* backend char plugin_path[MAX_PLUGIN_PATH] = ""; void* handle = NULL; - if(strlen(path) >= sizeof(plugin_path) - 30){ + if(strlen(path) >= sizeof(plugin_path) - 30 || strlen(path) == 0){ fprintf(stderr, "Plugin path length exceeds limit\n"); return 1; } |
