[Pkg-privacy-commits] [onionshare] 196/256: #345 - validate the readability of files before adding them

Ulrike Uhlig ulrike at moszumanska.debian.org
Fri May 26 12:53:40 UTC 2017


This is an automated email from the git hooks/post-receive script.

ulrike pushed a commit to branch master
in repository onionshare.

commit 8a1fad7a79062be0cf5fce8395726658e38f5aea
Author: Miguel Jacq <mig at mig5.net>
Date:   Thu May 18 18:09:49 2017 +1000

    #345 - validate the readability of files before adding them
---
 onionshare/__init__.py           | 3 +++
 onionshare_gui/__init__.py       | 4 ++++
 onionshare_gui/file_selection.py | 6 +++++-
 share/locale/en.json             | 1 +
 4 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/onionshare/__init__.py b/onionshare/__init__.py
index 145a25b..f799ea0 100644
--- a/onionshare/__init__.py
+++ b/onionshare/__init__.py
@@ -67,6 +67,9 @@ def main(cwd=None):
         if not os.path.exists(filename):
             print(strings._("not_a_file").format(filename))
             valid = False
+        if not os.access(filename, os.R_OK):
+            print(strings._("not_a_readable_file").format(filename))
+            valid = False
     if not valid:
         sys.exit()
 
diff --git a/onionshare_gui/__init__.py b/onionshare_gui/__init__.py
index 3cc4c07..b486b83 100644
--- a/onionshare_gui/__init__.py
+++ b/onionshare_gui/__init__.py
@@ -19,6 +19,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 from __future__ import division
 import os, sys, platform, argparse
+from .alert import Alert
 from PyQt5 import QtCore, QtWidgets
 
 from onionshare import strings, common, web
@@ -88,6 +89,9 @@ def main():
             if not os.path.exists(filename):
                 Alert(strings._("not_a_file", True).format(filename))
                 valid = False
+            if not os.access(filename, os.R_OK):
+                Alert(strings._("not_a_readable_file", True).format(filename))
+                valid = False
         if not valid:
             sys.exit()
 
diff --git a/onionshare_gui/file_selection.py b/onionshare_gui/file_selection.py
index 6accc11..49b811c 100644
--- a/onionshare_gui/file_selection.py
+++ b/onionshare_gui/file_selection.py
@@ -19,6 +19,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 import os
 from PyQt5 import QtCore, QtWidgets, QtGui
+from .alert import Alert
 
 from onionshare import strings, common
 
@@ -213,7 +214,10 @@ class FileSelection(QtWidgets.QVBoxLayout):
             caption=strings._('gui_choose_files', True), options=QtWidgets.QFileDialog.ReadOnly)
         if filenames:
             for filename in filenames[0]:
-                self.file_list.add_file(filename)
+                if not os.access(filename, os.R_OK):
+                    Alert(strings._("not_a_readable_file", True).format(filename))
+                else:
+                    self.file_list.add_file(filename)
         self.update()
 
     def add_dir(self):
diff --git a/share/locale/en.json b/share/locale/en.json
index 79e5277..701b067 100644
--- a/share/locale/en.json
+++ b/share/locale/en.json
@@ -9,6 +9,7 @@
     "give_this_url_stealth": "Give this URL and HidServAuth line to the person you're sending the file to:",
     "ctrlc_to_stop":  "Press Ctrl-C to stop server",
     "not_a_file": "{0:s} is not a file.",
+    "not_a_readable_file": "{0:s} is not a readable file.",
     "download_page_loaded": "Download page loaded",
     "other_page_loaded": "URL loaded",
     "closing_automatically": "Closing automatically because download finished",

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onionshare.git



More information about the Pkg-privacy-commits mailing list