From 5522507bd7ff51ad8a55f8318c327ace3157675d Mon Sep 17 00:00:00 2001 From: Roland Hochmuth Date: Sat, 21 Jul 2012 10:52:41 +0100 Subject: Return 400 in get_console_output for bad length. Fixes bug 1027069. Prior to this fix if the length in the request body was set to a non-integer value a error code of 500 was returned. The documentation also shows an integer in the example request body. The fix tests if the optional length is provided and if it is either an "int" or "long". If not, a 400 error is returned. Additionally, cleaned up some error message to be more descriptive. Change-Id: I27a66fb1111e74665969f98e1101a9c37c665abc --- nova/api/openstack/compute/contrib/console_output.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/compute/contrib/console_output.py b/nova/api/openstack/compute/contrib/console_output.py index 7a16daec3..c29177a07 100644 --- a/nova/api/openstack/compute/contrib/console_output.py +++ b/nova/api/openstack/compute/contrib/console_output.py @@ -49,14 +49,22 @@ class ConsoleOutputController(wsgi.Controller): try: length = body['os-getConsoleOutput'].get('length') except (TypeError, KeyError): - raise webob.exc.HTTPBadRequest(_('Malformed request body')) + raise webob.exc.HTTPBadRequest(_('os-getConsoleOutput malformed or ' + 'missing from request body')) + + if length is not None: + try: + int(length) + except ValueError: + raise webob.exc.HTTPBadRequest(_('Length in request body must ' + 'be an integer value')) try: output = self.compute_api.get_console_output(context, instance, length) except exception.NotFound: - raise webob.exc.HTTPNotFound(_('Instance not found')) + raise webob.exc.HTTPNotFound(_('Unable to get console')) # XML output is not correctly escaped, so remove invalid characters remove_re = re.compile('[\x00-\x08\x0B-\x0C\x0E-\x1F]') @@ -64,7 +72,6 @@ class ConsoleOutputController(wsgi.Controller): return {'output': output} - class Console_output(extensions.ExtensionDescriptor): """Console log output support, with tailing ability.""" -- cgit