Commit 56763837 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

scripts: Add ACT_MAX limit and make @action_names being const

@action_names is rather a const array, so make
sure we never access some data outside of it
defining its size.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 02d9bd10
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "cr-service.h" #include "cr-service.h"
#include "action-scripts.h" #include "action-scripts.h"
static char *action_names[] = { static const char *action_names[ACT_MAX] = {
[ ACT_POST_DUMP ] = "post-dump", [ ACT_POST_DUMP ] = "post-dump",
[ ACT_POST_RESTORE ] = "post-restore", [ ACT_POST_RESTORE ] = "post-restore",
[ ACT_NET_LOCK ] = "network-lock", [ ACT_NET_LOCK ] = "network-lock",
...@@ -24,7 +24,7 @@ int run_scripts(enum script_actions act) ...@@ -24,7 +24,7 @@ int run_scripts(enum script_actions act)
struct script *script; struct script *script;
int ret = 0; int ret = 0;
char image_dir[PATH_MAX]; char image_dir[PATH_MAX];
char *action = action_names[act]; const char *action = action_names[act];
pr_debug("Running %s scripts\n", action); pr_debug("Running %s scripts\n", action);
...@@ -42,7 +42,7 @@ int run_scripts(enum script_actions act) ...@@ -42,7 +42,7 @@ int run_scripts(enum script_actions act)
list_for_each_entry(script, &opts.scripts, node) { list_for_each_entry(script, &opts.scripts, node) {
if (script->path == SCRIPT_RPC_NOTIFY) { if (script->path == SCRIPT_RPC_NOTIFY) {
pr_debug("\tRPC\n"); pr_debug("\tRPC\n");
ret |= send_criu_rpc_script(act, action, script->arg); ret |= send_criu_rpc_script(act, (char *)action, script->arg);
} else { } else {
pr_debug("\t[%s]\n", script->path); pr_debug("\t[%s]\n", script->path);
ret |= system(script->path); ret |= system(script->path);
......
...@@ -10,11 +10,13 @@ struct script { ...@@ -10,11 +10,13 @@ struct script {
#define SCRIPT_RPC_NOTIFY (char *)0x1 #define SCRIPT_RPC_NOTIFY (char *)0x1
enum script_actions { enum script_actions {
ACT_POST_DUMP, ACT_POST_DUMP = 0,
ACT_POST_RESTORE, ACT_POST_RESTORE = 1,
ACT_NET_LOCK, ACT_NET_LOCK = 2,
ACT_NET_UNLOCK, ACT_NET_UNLOCK = 3,
ACT_SETUP_NS, ACT_SETUP_NS = 4,
ACT_MAX
}; };
extern int add_script(char *path, int arg); extern int add_script(char *path, int arg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment