[libvirt] [PATCH] esx: Fix esxVI_String_Deserialize

It was broken since forever as it expected a libxml2 XML_ELEMENT_NODE containing a XML_TEXT_NODE instead of just a XML_TEXT_NODE. This problem was not discovered for so long because esxVI_String_Deserialize was not used until now. Reported by Ata Bohra --- src/esx/esx_vi_types.c | 23 +++++++++++++++++++---- 1 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c index bcc310f..844fb65 100644 --- a/src/esx/esx_vi_types.c +++ b/src/esx/esx_vi_types.c @@ -1227,11 +1227,26 @@ esxVI_String_SerializeValue(const char *value, const char *element, return 0; } -/* esxVI_String_Deserialize */ -ESX_VI__TEMPLATE__DESERIALIZE(String, +int +esxVI_String_Deserialize(xmlNodePtr node, esxVI_String **string) { - ESX_VI__TEMPLATE__PROPERTY__DESERIALIZE_VALUE(String, value) -}) + if (string == NULL || *string != NULL) { + ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); + return -1; + } + + if (esxVI_String_Alloc(string) < 0 || + esxVI_String_DeserializeValue(node, &(*string)->value) < 0) { + goto failure; + } + + return 0; + + failure: + esxVI_String_Free(string); + + return -1; +} /* esxVI_String_DeserializeList */ ESX_VI__TEMPLATE__LIST__DESERIALIZE(String) -- 1.7.4.1

On 07/18/2012 04:48 PM, Matthias Bolte wrote:
It was broken since forever as it expected a libxml2 XML_ELEMENT_NODE containing a XML_TEXT_NODE instead of just a XML_TEXT_NODE.
This problem was not discovered for so long because esxVI_String_Deserialize was not used until now.
Reported by Ata Bohra --- src/esx/esx_vi_types.c | 23 +++++++++++++++++++---- 1 files changed, 19 insertions(+), 4 deletions(-)
ACK. Even though you're adding lines of code...
-/* esxVI_String_Deserialize */ -ESX_VI__TEMPLATE__DESERIALIZE(String,
..the old code was a macro expanding into a much larger unwrap operation, and your new code is a subset of that with less unwrapping.
+ if (string == NULL || *string != NULL) { + ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
Conflict magnet, depending on whether your patch or Dan's error cleanup patch goes in first. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

2012/7/19 Eric Blake <eblake@redhat.com>:
On 07/18/2012 04:48 PM, Matthias Bolte wrote:
It was broken since forever as it expected a libxml2 XML_ELEMENT_NODE containing a XML_TEXT_NODE instead of just a XML_TEXT_NODE.
This problem was not discovered for so long because esxVI_String_Deserialize was not used until now.
Reported by Ata Bohra --- src/esx/esx_vi_types.c | 23 +++++++++++++++++++---- 1 files changed, 19 insertions(+), 4 deletions(-)
ACK. Even though you're adding lines of code...
-/* esxVI_String_Deserialize */ -ESX_VI__TEMPLATE__DESERIALIZE(String,
..the old code was a macro expanding into a much larger unwrap operation, and your new code is a subset of that with less unwrapping.
+ if (string == NULL || *string != NULL) { + ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
Conflict magnet, depending on whether your patch or Dan's error cleanup patch goes in first.
So I went ahead and pushed this one. Thanks :) -- Matthias Bolte http://photron.blogspot.com
participants (2)
-
Eric Blake
-
Matthias Bolte