From 943e91f74dcf28d0ff3ce71b785f04248ec08159 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Sat, 1 Dec 2012 19:16:26 +0100 Subject: [PATCH] [eit] convert all the sys.argv elements to unicode in main() This avoids potential issues with entropy.db and other entropy.server components. --- server/eit/main.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/server/eit/main.py b/server/eit/main.py index 4990969ab..f35c72a82 100644 --- a/server/eit/main.py +++ b/server/eit/main.py @@ -14,6 +14,7 @@ import sys import argparse from entropy.i18n import _ +from entropy.const import etpConst, const_convert_to_unicode from entropy.output import print_error import entropy.tools @@ -60,6 +61,17 @@ def main(): args_map[alias] = klass args = sys.argv[1:] + # convert args to unicode, to avoid passing + # raw string stuff down to entropy layers + def _to_unicode(arg): + try: + return const_convert_to_unicode( + arg, enctype=etpConst['conf_encoding']) + except UnicodeDecodeError: + print_error("invalid argument: %s" % (arg,)) + raise SystemExit(1) + args = list(map(_to_unicode, args)) + is_bashcomp = False if "--bashcomp" in args: is_bashcomp = True @@ -104,4 +116,3 @@ def main(): else: print_error(_("superuser access required")) raise SystemExit(1) -