Added exception handling for mal-formatted XML Parsing

In order to handle mal-formatted XML returned from Dogtag, added
exception handling around etree.fromstring function.

https://fedorahosted.org/freeipa/ticket/5885

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2016-05-09 10:31:24 +05:30 committed by Martin Basti
parent 84e5065b39
commit 2df25cb359

View File

@ -5,8 +5,9 @@
# Rob Crittenden <rcritten@@redhat.com>
# John Dennis <jdennis@redhat.com>
# Fraser Tweedale <ftweedal@redhat.com>
# Abhijeet Kasurde <akasurde@redhat.com>
#
# Copyright (C) 2014, 2015 Red Hat
# Copyright (C) 2014-2016 Red Hat, Inc.
# see file 'COPYING' for use and warranty information
#
# This program is free software; you can redistribute it and/or modify
@ -1380,7 +1381,11 @@ class ra(rabase.rabase):
to get the parsing result as a dict of key/value pairs.
'''
parser = etree.XMLParser()
doc = etree.fromstring(xml_text, parser)
try:
doc = etree.fromstring(xml_text, parser)
except etree.XMLSyntaxError as e:
self.raise_certificate_operation_error('get_parse_result_xml',
detail=str(e))
result = parse_func(doc)
self.debug("%s() xml_text:\n%s\n"
"parse_result:\n%s" % (parse_func.__name__, xml_text, result))