subuser-security / subuser

Run programs on linux with selectively restricted permissions.
http://subuser.org
GNU Lesser General Public License v3.0
890 stars 65 forks source link

Add missing GitException handling (fixes #338) #339

Closed DEVoytas closed 6 years ago

DEVoytas commented 6 years ago

Induce the issue:

git config --global init.templatedir "/tmp/non-existing"

without the fix:

$ rm -rf ~/.subuser && subuser list available                                                                                                                                                                      
warning: templates not found /tmp/non-existing
Traceback (most recent call last):
  File "/usr/local/bin/subuser", line 52, in <module>
    command(sys.argv[2:])
  File "/usr/local/lib/python3.5/dist-packages/subuserlib/builtInCommands/list.py", line 64, in runCommand
    reposToList = user.registry.repositories.keys()
  File "/usr/local/lib/python3.5/dist-packages/subuserlib/classes/user.py", line 70, in registry
    self.__registry.ensureGitRepoInitialized()
  File "/usr/local/lib/python3.5/dist-packages/subuserlib/classes/registry.py", line 62, in ensureGitRepoInitialized
    self.gitRepository.run(["init"])
  File "/usr/local/lib/python3.5/dist-packages/subuserlib/classes/gitRepository.py", line 60, in run
    returncode,_ = self.__run(args)
  File "/usr/local/lib/python3.5/dist-packages/subuserlib/classes/gitRepository.py", line 84, in __run
    raise GitException(stderr)
subuserlib.classes.gitRepository.GitException: warning: templates not found /tmp/non-existing

with the fix:

$ rm -rf ~/.subuser && subuser list available
warning: templates not found /tmp/non-existing
Git failed with: 'warning: templates not found /tmp/non-existing'.
timthelion commented 6 years ago

Thank you for your contribution.

GitException is actually raised a few lines above where you added the except statement and is caught in a couple of places:

So we need to continue to raise it, rather than failing immediately.

Can you please move the except statement to:

  File "/usr/local/lib/python3.5/dist-packages/subuserlib/classes/registry.py", line 62, in ensureGitRepoInitialized
    self.gitRepository.run(["init"])

https://github.com/subuser-security/subuser/blob/74f3c9a64eb1db206bd3cbfc94e81aee4e9e626c/logic/subuserlib/classes/registry.py#L62

DEVoytas commented 6 years ago

Like this: https://github.com/subuser-security/subuser/pull/339/commits/c468b295c7723298bec154fe34392e4ef737f4bf ?

timthelion commented 6 years ago

Looks good.