From f27db06b173c0a22f812888574c1a53ac4f8991a Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Tue, 6 Nov 2018 21:06:50 +0900 Subject: [PATCH] Disable overriding PATH environment variable #19 --- virtscreen/path.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/virtscreen/path.py b/virtscreen/path.py index de94aec..1b5d070 100644 --- a/virtscreen/path.py +++ b/virtscreen/path.py @@ -7,25 +7,24 @@ # Sanitize environment variables # https://wiki.sei.cmu.edu/confluence/display/c/ENV03-C.+Sanitize+the+environment+when+invoking+external+programs -# Delete $HOME env for security reason. This will make +# Setting home path +# Rewrite $HOME env for consistency. This will make # Path.home() to look up in the password directory (pwd module) -if 'HOME' in os.environ: - del os.environ['HOME'] -os.environ['HOME'] = str(Path.home()) -os.environ['PATH'] = os.confstr("CS_PATH") # Sanitize $PATH +try: + os.environ['HOME'] = str(Path.home()) + # os.environ['PATH'] = os.confstr("CS_PATH") # Sanitize $PATH, Deleted by Issue #19. -# Setting home path and base path -# https://www.freedesktop.org/software/systemd/man/file-hierarchy.html -# HOME_PATH will point to ~/.config/virtscreen by default -if 'XDG_CONFIG_HOME' in os.environ and os.environ['XDG_CONFIG_HOME']: - HOME_PATH = os.environ['XDG_CONFIG_HOME'] -else: - HOME_PATH = os.environ['HOME'] - if HOME_PATH is not None: - HOME_PATH = HOME_PATH + "/.config" -if HOME_PATH is not None: + # https://www.freedesktop.org/software/systemd/man/file-hierarchy.html + # HOME_PATH will point to ~/.config/virtscreen by default + if ('XDG_CONFIG_HOME' in os.environ) and len(os.environ['XDG_CONFIG_HOME']): + HOME_PATH = os.environ['XDG_CONFIG_HOME'] + else: + HOME_PATH = os.environ['HOME'] + '/.config' HOME_PATH = HOME_PATH + "/virtscreen" -BASE_PATH = os.path.dirname(__file__) +except OSError: + HOME_PATH = '' # This will be checked in _main_.py. +# Setting base path +BASE_PATH = os.path.dirname(__file__) # Location of this script # Path in ~/.virtscreen X11VNC_LOG_PATH = HOME_PATH + "/x11vnc_log.txt" X11VNC_PASSWORD_PATH = HOME_PATH + "/x11vnc_passwd"