From a111eeb8aebdfd27f8dca53b97ad3d090450c818 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Wed, 11 Nov 2015 12:25:19 +0000 Subject: [PATCH] Do more validation on --dir / --target directories (#7) Previously STOW_DIR=0 would cause the cwd to be used as the STOW_DIR. Make that instead raise an error. Do similar validation on the target directory. Closes #7 - https://github.com/aspiers/stow/pull/7 --- bin/stow.in | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/stow.in b/bin/stow.in index c437f29..1ebc695 100755 --- a/bin/stow.in +++ b/bin/stow.in @@ -542,12 +542,17 @@ sub sanitize_path_options { $options->{dir} =~ s/ +\z//; } else { - $options->{dir} = $ENV{STOW_DIR} ? $ENV{STOW_DIR} : getcwd(); + $options->{dir} = length $ENV{STOW_DIR} ? $ENV{STOW_DIR} : getcwd(); } + usage("--dir value '$options->{dir}' is not a valid directory") + unless -d $options->{dir}; + if (exists $options->{target}) { $options->{target} =~ s/\A +//; $options->{target} =~ s/ +\z//; + usage("--target value '$options->{target}' is not a valid directory") + unless -d $options->{target}; } else { $options->{target} = parent($options->{dir}) || '.';