diff options
author | Joursoir <chat@joursoir.net> | 2022-08-25 19:38:00 +0300 |
---|---|---|
committer | Joursoir <chat@joursoir.net> | 2022-08-25 20:36:12 +0300 |
commit | 95705e381b2256df902ae36f64167b882dba7548 (patch) | |
tree | b2b98c404e66ebd76c5ca22e5f8c5be298631f8a | |
parent | e0810c5c7ae73c5e12d20fb169507e121c6b01e1 (diff) | |
download | lock-password-95705e381b2256df902ae36f64167b882dba7548.tar.gz lock-password-95705e381b2256df902ae36f64167b882dba7548.tar.bz2 lock-password-95705e381b2256df902ae36f64167b882dba7548.zip |
tree: move printing error into check_sneaky_paths()
Avoid repeating the same error messages.
-rw-r--r-- | src/exec-cmd.c | 30 | ||||
-rw-r--r-- | src/routines.c | 5 |
2 files changed, 13 insertions, 22 deletions
diff --git a/src/exec-cmd.c b/src/exec-cmd.c index 570bdb5..1bfc3ff 100644 --- a/src/exec-cmd.c +++ b/src/exec-cmd.c @@ -95,10 +95,8 @@ int cmd_insert(int argc, char *argv[]) } result = check_sneaky_paths(path); - if(result) { - print_error("Error: You have used forbidden paths\n"); + if(result) return 1; - } if(file_exist(path) == F_ISFILE) { if(!flag_force) { @@ -176,10 +174,8 @@ int cmd_edit(int argc, char *argv[]) } result = check_sneaky_paths(path); - if(result) { - print_error("Error: You have used forbidden paths\n"); + if(result) return 1; - } result = file_exist(path); if(result == F_NOEXIST) { @@ -304,10 +300,8 @@ int cmd_generate(int argc, char *argv[]) } result = check_sneaky_paths(path); - if(result) { - print_error("Error: You have used forbidden paths\n"); + if(result) return 1; - } result = file_exist(path); if(result == F_ISFILE) { @@ -351,10 +345,8 @@ int cmd_remove(int argc, char *argv[]) } result = check_sneaky_paths(path); - if(result) { - print_error("Error: You have used forbidden paths\n"); + if(result) return 1; - } result = file_exist(path); if(result == F_NOEXIST) { @@ -409,10 +401,9 @@ int cmd_move(int argc, char *argv[]) dbgprint("new-path = %s\n", new_path); result = check_sneaky_paths(old_path); - if(result) { - print_error("Error: You have used forbidden paths\n"); + if(result) return 1; - } + result = file_exist(old_path); if(result == F_NOEXIST) { print_error("Error: No such file exists\n"); @@ -420,10 +411,9 @@ int cmd_move(int argc, char *argv[]) } result = check_sneaky_paths(new_path); - if(result) { - print_error("Error: You have used forbidden paths\n"); + if(result) return 1; - } + result = file_exist(new_path); if(result != F_NOEXIST) { if(!flag_force) { @@ -506,10 +496,8 @@ int cmd_showtree(int argc, char *argv[]) const char *path = "."; if(argv[optind]) { result = check_sneaky_paths(argv[optind]); - if(result) { - print_error("Error: You have used forbidden paths\n"); + if(result) return 1; - } path = argv[optind]; } diff --git a/src/routines.c b/src/routines.c index 09916aa..21c569b 100644 --- a/src/routines.c +++ b/src/routines.c @@ -33,6 +33,7 @@ #if defined(DISPLAY) #include "r-x11.h" #endif +#include "output.h" #define NUMBER_ALLOWED_CHARS (10+26+26+8) @@ -72,8 +73,10 @@ int check_sneaky_paths(const char *path) int length = strlen(path), i; for(i = 1; i < length; i++) { - if(path[i-1] == '.' && path[i] == '.') + if(path[i-1] == '.' && path[i] == '.') { + print_error("Error: You have used forbidden paths\n"); return 1; + } } return 0; } |