Michael Pasternak has uploaded a new change for review.

Change subject: sdk: defend against malformed server reply
......................................................................

sdk: defend against malformed server reply

Change-Id: I236863ab9fee7b5af43402f1beb055dc6ea0e39b
Signed-off-by: Michael Pasternak <[email protected]>
---
M src/codegen/templates/entrypointtemplate
M src/ovirtsdk/api.py
M src/ovirtsdk/infrastructure/errors.py
M src/ovirtsdk/infrastructure/proxy.py
4 files changed, 24 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-sdk refs/changes/86/12486/1

diff --git a/src/codegen/templates/entrypointtemplate 
b/src/codegen/templates/entrypointtemplate
index fdf125d..e4c8e47 100644
--- a/src/codegen/templates/entrypointtemplate
+++ b/src/codegen/templates/entrypointtemplate
@@ -24,6 +24,7 @@
         @raise MissingParametersError: raised when get() method invoked 
without id or name been specified.
         @raise ConnectionError: raised when any kind of communication error 
occurred.
         @raise RequestError: raised when any kind of oVirt server error 
occurred.
+        @raise FormatError: raised when server replies in non-XML format.
         '''
 
         # The instance id
diff --git a/src/ovirtsdk/api.py b/src/ovirtsdk/api.py
index f13a881..653fc13 100644
--- a/src/ovirtsdk/api.py
+++ b/src/ovirtsdk/api.py
@@ -76,6 +76,7 @@
         @raise MissingParametersError: raised when get() method invoked 
without id or name been specified.
         @raise ConnectionError: raised when any kind of communication error 
occurred.
         @raise RequestError: raised when any kind of oVirt server error 
occurred.
+        @raise FormatError: raised when server replies in non-XML format.
         '''
 
         # The instance id
diff --git a/src/ovirtsdk/infrastructure/errors.py 
b/src/ovirtsdk/infrastructure/errors.py
index 544f4f2..a197770 100644
--- a/src/ovirtsdk/infrastructure/errors.py
+++ b/src/ovirtsdk/infrastructure/errors.py
@@ -97,3 +97,7 @@
 class ImmutableError(Exception):
     def __init__(self, key):
         Exception.__init__(self, '[ERROR]::\'%s\' is immutable.' % key)
+
+class FormatError(Exception):
+    def __init__(self):
+        Exception.__init__(self, '[ERROR]::Server reply is in inappropriate 
format.')
diff --git a/src/ovirtsdk/infrastructure/proxy.py 
b/src/ovirtsdk/infrastructure/proxy.py
index 992a199..4dd5188 100644
--- a/src/ovirtsdk/infrastructure/proxy.py
+++ b/src/ovirtsdk/infrastructure/proxy.py
@@ -18,9 +18,11 @@
 import socket
 import urlparse
 
-from ovirtsdk.infrastructure.errors import RequestError, ConnectionError
+from ovirtsdk.infrastructure.errors import RequestError, ConnectionError, \
+    FormatError
 from ovirtsdk.xml import params
 from cookielib import DefaultCookiePolicy
+from lxml import etree
 
 class CookieJarAdapter():
     """
@@ -231,8 +233,8 @@
             # Print response body (if in debug mode)
             self.__do_debug(conn, response_body)
 
-            if not noParse and (response_body is not None and response_body is 
not ''):
-                return params.parseString(response_body)
+            if not noParse:
+                return self.__xml2py(response_body)
             return response_body
 
         except socket.error, e:
@@ -240,6 +242,19 @@
         finally:
             conn.close()
 
+    def __xml2py(self, obj):
+        '''
+        Parse XML in to python entity
+        '''
+        if obj is not None and obj is not '':
+            try:
+                return params.parseString(obj)
+            except etree.XMLSyntaxError:
+                # raised when server replies in non-XML format,
+                # the motivation for this error is #915036
+                raise FormatError
+        return obj
+
     def __do_debug(self, conn, body):
         '''
         Prints request body (when in debug) to STDIO


--
To view, visit http://gerrit.ovirt.org/12486
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I236863ab9fee7b5af43402f1beb055dc6ea0e39b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-sdk
Gerrit-Branch: sdk_3.2
Gerrit-Owner: Michael Pasternak <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to