Fix 500 if list servers called with empty regex pattern
If nova list API is called with empty regex pattern like below:
http://<host-ip>/compute/v2.1/servers?name=""
it fails at db layer and returns 500 InternalServerError.
Empty string('') is a valid regex for re.compile [1] so nova-api fails
to catch it at schema layer and it is passed to databse for searching.
Database fails to search it with "REGEXP %(display_name_1)s)" and
'display_name_1' as u'' in sql query which leads to below error:
InternalError: (1139, u"Got error 'empty (sub)expression' from regexp")
This issue is there for every query parameter which is using below
regex parameter types defined in parameter_types.py: common_query_regex_param
This patch fixes this issue by rejecting the request with 400 if the
provided filter regex is empty string. If user is intending to filter
something, user must pass something to the filter, it cannot be a empty
string.
Reviewed: https:/ /review. openstack. org/506754 /git.openstack. org/cgit/ openstack/ nova/commit/ ?id=6538175c08f 127c20e72e1d347 af3eb3d54d6838
Committed: https:/
Submitter: Jenkins
Branch: stable/pike
commit 6538175c08f127c 20e72e1d347af3e b3d54d6838
Author: Dinesh Bhor <email address hidden>
Date: Tue Sep 19 14:56:01 2017 +0530
Fix 500 if list servers called with empty regex pattern
If nova list API is called with empty regex pattern like below: /compute/ v2.1/servers? name=""
http://<host-ip>
it fails at db layer and returns 500 InternalServerE rror.
Empty string('') is a valid regex for re.compile [1] so nova-api fails name_1) s)" and name_1' as u'' in sql query which leads to below error:
to catch it at schema layer and it is passed to databse for searching.
Database fails to search it with "REGEXP %(display_
'display_
InternalError: (1139, u"Got error 'empty (sub)expression' from regexp")
This issue is there for every query parameter which is using below
common_ query_regex_ param
regex parameter types defined in parameter_types.py:
This patch fixes this issue by rejecting the request with 400 if the
provided filter regex is empty string. If user is intending to filter
something, user must pass something to the filter, it cannot be a empty
string.
[1] https:/ /github. com/openstack/ nova/blob/ 16.0.0/ nova/api/ validation/ validators. py#L40
Closes-Bug: #1718877 79964e8e5dd2a79 0b997a40e4e 3cb8d739e132b52 fa40bcddb0)
Change-Id: I3f6fa04dc72672
(cherry picked from commit 0cc94bfd5934e79