Browse Source

* use f2b_cmd_check_argc() in f2b_cmsg_process()

master
Alex 'AdUser' Z 8 years ago
parent
commit
4e4a62893d
  1. 2
      src/CMakeLists.txt
  2. 16
      src/daemon.c

2
src/CMakeLists.txt

@ -3,7 +3,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(SOURCES "daemon.c" "strlcpy.c" "config.c" "log.c" "matches.c" "ipaddr.c" "source.c" "filter.c" "backend.c" "jail.c")
if (WITH_CSOCKET)
list(APPEND SOURCES "csocket.c" "cmsg.c")
list(APPEND SOURCES "commands.c" "csocket.c" "cmsg.c")
add_definitions("-DWITH_CSOCKET")
endif ()

16
src/daemon.c

@ -96,26 +96,20 @@ f2b_cmsg_process(const f2b_cmsg_t *msg, char *res, size_t ressize) {
return;
memset(args, 0x0, sizeof(args));
f2b_cmsg_extract_args(msg, args);
int argc = f2b_cmsg_extract_args(msg, args);
if (msg->type >= CMD_JAIL_STATUS && msg->type <= CMD_MAX_NUMBER) {
if (args[0] == NULL) {
strlcpy(res, "can't find jail: no args\n", ressize);
if (f2b_cmd_check_argc(msg->type, argc) == false) {
strlcpy(res, "cms args number mismatch", ressize);
return;
}
if (msg->type >= CMD_JAIL_STATUS && msg->type <= CMD_MAX_NUMBER) {
if ((jail = f2b_jail_find(jails, args[0])) == NULL) {
snprintf(res, ressize, "can't find jail '%s'\n", args[0]);
return;
}
}
if (jail && (msg->type >= CMD_JAIL_IP_SHOW && msg->type <= CMD_JAIL_IP_RELEASE)) {
if (args[1] == NULL) {
strlcpy(res, "can't find ip: no args", ressize);
return;
}
}
if (msg->type == CMD_PING) {
strlcpy(res, "ok", ressize);
} else if (msg->type == CMD_RELOAD) {

Loading…
Cancel
Save