mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 10:51:54 -04:00
Validate the smartctl string before accepting it
This commit is contained in:
parent
0477ed36c6
commit
4af4504515
1 changed files with 37 additions and 0 deletions
|
|
@ -415,6 +415,36 @@ static void state_config_check(struct snapraid_state* state, const char* path, t
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the smartctl command.
|
||||
*
|
||||
* It must contains only one %s string, and not other % chars.
|
||||
*/
|
||||
static int validate_smartctl(const char* custom)
|
||||
{
|
||||
const char* s = custom;
|
||||
int arg = 0;
|
||||
|
||||
while (*s) {
|
||||
if (s[0] == '%' && s[1] == 's') {
|
||||
if (arg) {
|
||||
/* LCOV_EXCL_START */
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
arg = 1;
|
||||
} else if (s[0] == '%') {
|
||||
/* LCOV_EXCL_START */
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
++s;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void state_config(struct snapraid_state* state, const char* path, const char* command, struct snapraid_option* opt, tommy_list* filterlist_disk)
|
||||
{
|
||||
STREAM* f;
|
||||
|
|
@ -792,6 +822,13 @@ void state_config(struct snapraid_state* state, const char* path, const char* co
|
|||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
if (validate_smartctl(custom) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
msg_error("Invalid 'smartctl' option specification in '%s' at line %u\n", path, line);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
/* search for parity */
|
||||
if (lev_config_scan(buffer, &level, 0) == 0) {
|
||||
if (state->parity[level].smartctl[0] != 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue