From 0774cc63011e7a68954649b101a16f4a7bf3fd35 Mon Sep 17 00:00:00 2001 From: Jason Hiser <jdhiser@gmail.com> Date: Thu, 15 Aug 2019 15:02:34 -0400 Subject: [PATCH] safety check for pedi --- pedi.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pedi.cpp b/pedi.cpp index 16455c6..a56c752 100644 --- a/pedi.cpp +++ b/pedi.cpp @@ -14,6 +14,9 @@ #include <sys/stat.h> #include <unistd.h> #include <dirent.h> +#include <limits.h> +#include <stdlib.h> +#include <assert.h> using namespace std; @@ -173,6 +176,23 @@ void parse_args(int argc, char* argv[]) exit(1); } } + + char cwd[PATH_MAX] = {}; + char real_cwd[PATH_MAX] = {}; + char real_install[PATH_MAX] = {}; + const auto cwd_res = getcwd(cwd, sizeof(cwd)); + const auto realpath_res1 = realpath(cwd,real_cwd); + const auto realpath_res2 = realpath(my_options.install_dir.c_str(),real_install); + assert(cwd_res != nullptr); + assert(realpath_res1 != nullptr); + assert(realpath_res1 != nullptr); + + if(string(real_cwd) == real_install) + { + cout << "Whoa, you don't want me to install into your root location, do you?!" << endl; + cout << "You'll lose all your files in " << real_cwd << endl; + exit(1); + } } -- GitLab