malformed JSON request body returns 500 error and stack trace

Bug #1039901 reported by IWAMOTO Toshihiro
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Glance
Fix Released
Medium
Alex Meade

Bug Description

Sending malformed JSON body, for example
$ echo 'foo'|curl -v -H 'X-Auth-Token: token' -H 'Content-Type: application/json' -X POST -T - http://glance-host:9292/v2/images
causes JSON decoder exception and returns a stack trace.

[snip]
  File "/opt/stack-gh/glance/glance/api/v2/images.py", line 228, in create
    def _check_reserved(image):
  File "/opt/stack-gh/glance/glance/api/v2/images.py", line 175, in _parse_image
    raise webob.exc.HTTPForbidden(explanation=msg)
  File "/opt/stack-gh/glance/glance/common/wsgi.py", line 462, in default
    return {'body': self.from_json(request.body)}
  File "/opt/stack-gh/glance/glance/common/wsgi.py", line 458, in from_json
    return json.loads(datastring)
  File "/usr/lib/python2.7/json/__init__.py", line 326, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

It seems JSONRequestDeserializer.from_json needs to wrap exceptions.

Alex Meade (alex-meade)
Changed in glance:
status: New → In Progress
assignee: nobody → Alex Meade (alex-meade)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to glance (master)

Fix proposed to branch: master
Review: https://review.openstack.org/11873

Brian Waldon (bcwaldon)
Changed in glance:
importance: Undecided → Medium
milestone: none → folsom-rc1
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to glance (master)

Reviewed: https://review.openstack.org/11873
Committed: http://github.com/openstack/glance/commit/f8467bfcef0795153fa7b6488bf866b6628669af
Submitter: Jenkins
Branch: master

commit f8467bfcef0795153fa7b6488bf866b6628669af
Author: Alex Meade <email address hidden>
Date: Thu Aug 23 11:10:28 2012 -0400

    HTTPBadRequest in v2 on malformed JSON request body.

    Fixes bug 1039901

    Change-Id: I79ff2059f8f4de60cc92f8cf89cd80be74529e3c

Changed in glance:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in glance:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in glance:
milestone: folsom-rc1 → 2012.2
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.