gui: improvements of feature keyboard layout checks

This commit is contained in:
Frédéric Pierret (fepitre) 2020-03-18 09:46:21 +01:00
parent 5cb0e61a84
commit f130ec0bf3
No known key found for this signature in database
GPG Key ID: 484010B5CDC576E2

View File

@ -126,16 +126,18 @@ class GUI(qubes.ext.Extension):
def on_feature_pre_set(self, subject, event, feature, value, oldvalue=None):
untrusted_xkb_layout = value.split('+')
if not len(untrusted_xkb_layout) == 3:
raise qubes.exc.QubesValueError
raise qubes.exc.QubesValueError("Invalid number of parameters")
untrusted_layout = untrusted_xkb_layout[0]
untrusted_variant = untrusted_xkb_layout[1]
untrusted_options = untrusted_xkb_layout[2]
re_variant = '^[a-zA-Z0-9-_]+$'
re_options = '^[a-zA-Z0-9-_:,]+$'
re_variant = r'^[a-zA-Z0-9-_]*$'
re_options = r'^[a-zA-Z0-9-_:,]*$'
if not untrusted_layout.isalpha() or \
not bool(re.match(re_variant, untrusted_variant)) or \
not bool(re.match(re_options, untrusted_options)):
raise qubes.exc.QubesValueError
if not untrusted_layout.isalpha():
raise qubes.exc.QubesValueError("Invalid layout provided")
if not bool(re.match(re_variant, untrusted_variant)):
raise qubes.exc.QubesValueError("Invalid variant provided")
if not bool(re.match(re_options, untrusted_options)):
raise qubes.exc.QubesValueError("Invalid options provided")