From: Anoop Saldanha Date: Fri, 22 Jun 2012 09:36:55 +0000 (+0530) Subject: util action api returns error code if it encounters wrong values parsing wrong action... X-Git-Tag: suricata-1.3rc1~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f5af4c9ceb5aa2b7ee863fa5cccedea6c55907f9;p=thirdparty%2Fsuricata.git util action api returns error code if it encounters wrong values parsing wrong action conf --- diff --git a/src/suricata.c b/src/suricata.c index 7f78bd1458..d21d035e9b 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -1650,7 +1650,9 @@ int main(int argc, char **argv) SCClassConfLoadClassficationConfigFile(de_ctx); SCRConfLoadReferenceConfigFile(de_ctx); - ActionInitConfig(); + if (ActionInitConfig() < 0) { + exit(EXIT_FAILURE); + } if (MagicInit() != 0) exit(EXIT_FAILURE); diff --git a/src/util-action.c b/src/util-action.c index 4ba1b47a55..8d8ae66c98 100644 --- a/src/util-action.c +++ b/src/util-action.c @@ -90,9 +90,10 @@ uint8_t ActionAsciiToFlag(char *action) { * \brief Load the action order from config. If none is provided, * it will be default to ACTION_PASS, ACTION_DROP, * ACTION_REJECT, ACTION_ALERT (pass has the highest prio) - * \retval none + * + * \retval 0 on success; -1 on fatal error; */ -void ActionInitConfig() { +int ActionInitConfig() { uint8_t actions_used = 0; uint8_t action_flag = 0; uint8_t actions_config[4] = {0, 0, 0, 0}; @@ -112,7 +113,7 @@ void ActionInitConfig() { " \"pass\",\"drop\",\"alert\",\"reject\". You have" " to specify all of them, without quotes and without" " capital letters", action->val); - return; + goto error; } if (actions_used & action_flag) { @@ -120,7 +121,7 @@ void ActionInitConfig() { " use \"pass\",\"drop\",\"alert\",\"reject\". You" " have to specify all of them, without quotes and" " without capital letters", action->val); - return; + goto error; } if (order >= 4) { @@ -129,7 +130,7 @@ void ActionInitConfig() { "\"drop\",\"alert\",\"reject\". You have to specify" " all of them, without quotes and without capital" " letters", action->val); - return; + goto error; } actions_used |= action_flag; actions_config[order++] = action_flag; @@ -140,13 +141,18 @@ void ActionInitConfig() { "actions. Please, use \"pass\",\"drop\",\"alert\"," "\"reject\". You have to specify all of them, without" " quotes and without capital letters"); - return; + goto error; } /* Now, it's a valid config. Override the default preset */ for (order = 0; order < 4; order++) { action_order_sigs[order] = actions_config[order]; } + + return 0; + + error: + return -1; } #ifdef UNITTESTS diff --git a/src/util-action.h b/src/util-action.h index 53aa4caf78..bc71131443 100644 --- a/src/util-action.h +++ b/src/util-action.h @@ -24,7 +24,7 @@ #ifndef __ACTION_ORDER_H__ #define __ACTION_ORDER_H__ #include "suricata-common.h" -void ActionInitConfig(); +int ActionInitConfig(); uint8_t ActionOrderVal(uint8_t); void UtilActionRegisterTests(void);