From 00e1ca599717d2294f084a618a328fd9e051943d Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Tue, 26 Jul 2016 20:56:21 +0200 Subject: [PATCH] Enforce a check on the content parity level This to avoid that damaged files cause a crash. --- cmdline/state.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/cmdline/state.c b/cmdline/state.c index 8b042ed0..dfc2de2e 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -2636,9 +2636,19 @@ static void state_read_content(struct snapraid_state* state, const char* path, S /* LCOV_EXCL_STOP */ } + if (v_level >= LEV_MAX) { + /* LCOV_EXCL_START */ + decoding_error(path, f); + log_fatal("Invalid parity level '%u' in the configuration file!\n", v_level); + exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } + /* auto configure if configuration is missing */ - if (state->no_conf && v_level < LEV_MAX && v_level >= state->level) - state->level = v_level + 1; + if (state->no_conf) { + if (v_level >= state->level) + state->level = v_level + 1; + } /* if we use this parity entry */ if (v_level < state->level) { @@ -2688,9 +2698,17 @@ static void state_read_content(struct snapraid_state* state, const char* path, S /* LCOV_EXCL_STOP */ } + if (v_level >= LEV_MAX) { + /* LCOV_EXCL_START */ + decoding_error(path, f); + log_fatal("Invalid parity level '%u' in the configuration file!\n", v_level); + exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } + /* auto configure if configuration is missing */ if (state->no_conf) { - if (v_level < LEV_MAX && v_level >= state->level) + if (v_level >= state->level) state->level = v_level + 1; if (state->parity[v_level].split_mac < v_split_mac) state->parity[v_level].split_mac = v_split_mac;