[CRIU] [PATCH] scripts: Add ACT_MAX limit and make @action_names being const
Cyrill Gorcunov
gorcunov at openvz.org
Fri Oct 24 12:07:15 PDT 2014
@action_names is rather a const array, so make
sure we never access some data outside of it
defining its size.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
action-scripts.c | 6 +++---
include/action-scripts.h | 12 +++++++-----
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/action-scripts.c b/action-scripts.c
index f8537c49088a..ca1f5e018ae1 100644
--- a/action-scripts.c
+++ b/action-scripts.c
@@ -11,7 +11,7 @@
#include "cr-service.h"
#include "action-scripts.h"
-static char *action_names[] = {
+static const char *action_names[ACT_MAX] = {
[ ACT_POST_DUMP ] = "post-dump",
[ ACT_POST_RESTORE ] = "post-restore",
[ ACT_NET_LOCK ] = "network-lock",
@@ -24,7 +24,7 @@ int run_scripts(enum script_actions act)
struct script *script;
int ret = 0;
char image_dir[PATH_MAX];
- char *action = action_names[act];
+ const char *action = action_names[act];
pr_debug("Running %s scripts\n", action);
@@ -42,7 +42,7 @@ int run_scripts(enum script_actions act)
list_for_each_entry(script, &opts.scripts, node) {
if (script->path == SCRIPT_RPC_NOTIFY) {
pr_debug("\tRPC\n");
- ret |= send_criu_rpc_script(act, action, script->arg);
+ ret |= send_criu_rpc_script(act, (char *)action, script->arg);
} else {
pr_debug("\t[%s]\n", script->path);
ret |= system(script->path);
diff --git a/include/action-scripts.h b/include/action-scripts.h
index f7aceaf596b6..684221f3c78d 100644
--- a/include/action-scripts.h
+++ b/include/action-scripts.h
@@ -10,11 +10,13 @@ struct script {
#define SCRIPT_RPC_NOTIFY (char *)0x1
enum script_actions {
- ACT_POST_DUMP,
- ACT_POST_RESTORE,
- ACT_NET_LOCK,
- ACT_NET_UNLOCK,
- ACT_SETUP_NS,
+ ACT_POST_DUMP = 0,
+ ACT_POST_RESTORE = 1,
+ ACT_NET_LOCK = 2,
+ ACT_NET_UNLOCK = 3,
+ ACT_SETUP_NS = 4,
+
+ ACT_MAX
};
extern int add_script(char *path, int arg);
--
1.9.3
More information about the CRIU
mailing list