Browse Source

* use strl*() instead snprintf() in backends

master
Alex 'AdUser' Z 8 years ago
parent
commit
fa1d35549c
  1. 4
      src/backends/CMakeLists.txt
  2. 4
      src/backends/exec.c
  3. 13
      src/backends/redis.c

4
src/backends/CMakeLists.txt

@ -1,12 +1,12 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(BACKENDS "")
add_library("f2b_backend_exec" MODULE "exec.c")
add_library("f2b_backend_exec" MODULE "exec.c" "../strlcpy.c")
list(APPEND BACKENDS "f2b_backend_exec")
find_library(REDIS_FOUND "pcre")
if (WITH_REDIS AND REDIS_FOUND)
add_library("f2b_backend_redis" MODULE "redis.c")
add_library("f2b_backend_redis" MODULE "redis.c" "../strlcpy.c")
target_link_libraries("f2b_backend_redis" "hiredis")
list(APPEND BACKENDS "f2b_backend_redis")
endif ()

4
src/backends/exec.c

@ -13,6 +13,8 @@
#include <sys/wait.h>
#include <unistd.h>
#include "../strlcpy.h"
#include "backend.h"
#include "shared.c"
@ -157,7 +159,7 @@ create(const char *id) {
if ((cfg = calloc(1, sizeof(cfg_t))) == NULL)
return NULL;
snprintf(cfg->name, sizeof(cfg->name), "%s", id);
strlcpy(cfg->name, id, sizeof(cfg->name));
return cfg;
}

13
src/backends/redis.c

@ -17,6 +17,8 @@
#include <hiredis/hiredis.h>
#include "../strlcpy.h"
#include "backend.h"
#include "shared.c"
@ -98,8 +100,9 @@ create(const char *id) {
if ((cfg = calloc(1, sizeof(cfg_t))) == NULL)
return NULL;
snprintf(cfg->name, sizeof(cfg->name), "%s", id);
snprintf(cfg->hash, sizeof(cfg->hash), "f2b-banned-%s", id);
strlcpy(cfg->name, id, sizeof(cfg->name));
strlcpy(cfg->hash, "f2b-banned-", sizeof(cfg->hash));
strlcat(cfg->hash, id, sizeof(cfg->hash));
return cfg;
}
@ -119,7 +122,7 @@ config(cfg_t *cfg, const char *key, const char *value) {
return true;
}
if (strcmp(key, "host") == 0) {
snprintf(cfg->host, sizeof(cfg->host), "%s", value);
strlcpy(cfg->host, value, sizeof(cfg->host));
return true;
}
if (strcmp(key, "port") == 0) {
@ -131,7 +134,7 @@ config(cfg_t *cfg, const char *key, const char *value) {
return true;
}
if (strcmp(key, "password") == 0) {
snprintf(cfg->password, sizeof(cfg->password), "%s", value);
strlcpy(cfg->password, value, sizeof(cfg->password));
return true;
}
@ -239,7 +242,7 @@ ping(cfg_t *cfg) {
if (reply) {
bool result = true;
if (reply->type == REDIS_REPLY_ERROR) {
snprintf(cfg->error, sizeof(cfg->error), "%s", reply->str);
strlcpy(cfg->error, reply->str, sizeof(cfg->error));
result = false;
}
freeReplyObject(reply);

Loading…
Cancel
Save