From eeeef17cc1bc830f2201574228830ac8a80f4c12 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jun 21 2017 09:14:50 +0000 Subject: Don't allow not-null empty arch/userID in listHosts Related: https://pagure.io/koji/issue/463 If empty string is passed, resulting SQL query is not valid. Check also channelID/userID to be an integer. --- diff --git a/hub/kojihub.py b/hub/kojihub.py index d300038..ce4c61c 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -10498,27 +10498,29 @@ class RootExports(object): clauses = [] joins = [] - if arches != None: + if arches is not None: + if not arches: + raise koji.GenericError('arches option cannot be empty') # include the regex constraints below so we can match 'ppc' without # matching 'ppc64' if not (isinstance(arches, list) or isinstance(arches, tuple)): arches = [arches] archClause = [r"""arches ~ E'\\m%s\\M'""" % arch for arch in arches] clauses.append('(' + ' OR '.join(archClause) + ')') - if channelID != None: + if channelID is not None: joins.append('host_channels on host.id = host_channels.host_id') clauses.append('host_channels.channel_id = %(channelID)i') - if ready != None: + if ready is not None: if ready: clauses.append('ready is true') else: clauses.append('ready is false') - if enabled != None: + if enabled is not None: if enabled: clauses.append('enabled is true') else: clauses.append('enabled is false') - if userID != None: + if userID is not None: clauses.append('user_id = %(userID)i') query = QueryProcessor(columns=fields, tables=['host'],