[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [libvirt-php] Fix get_xml when xpath is null



Hi all:

	To my surprise, it seems that passing null to php as a string parameter,
will set the pointer which retrive it to an empty string "" , but not NULL.
get_xml_from_xpath() doesn't work correctly since an empty string is 
passed as the xpath argument, and libxml will complain "Invalid expression"

I know seldom about xpath, I'm not sure if it is the correct way to fix it.

BTW, what xpath shall I pass to get the entire xml?

---
 src/libvirt-php.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index ce9d0b9..2a77423 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -1205,6 +1205,11 @@ char *get_string_from_xpath(char *xml, char *xpath, zval **val, int *retVal)
 	int ret = 0, i;
 	char *value, key[8] = { 0 };
 
+	if ((xpath == NULL) || (xml == NULL))
+	{
+		return NULL;
+	}
+
 	xp = xmlCreateDocParserCtxt( (xmlChar *)xml );
 	if (!xp) {
 		if (retVal)
@@ -1691,6 +1696,10 @@ PHP_FUNCTION(libvirt_domain_get_xml_desc)
 	int retval = -1;
 
 	GET_DOMAIN_FROM_ARGS("rs|l",&zdomain,&xpath,&xpath_len,&flags);
+	if (xpath_len < 1)
+	{
+		xpath = NULL;
+	}
 
 	xml=virDomainGetXMLDesc(domain->domain,flags);
 	if (xml==NULL) {
@@ -3123,6 +3132,10 @@ PHP_FUNCTION(libvirt_storagevolume_get_xml_desc)
 	int retval = -1;
 
 	GET_VOLUME_FROM_ARGS("rs|l",&zvolume,&xpath,&xpath_len,&flags);
+	if (xpath_len < 1)
+	{
+		xpath = NULL;
+	}
 
 	xml=virStorageVolGetXMLDesc(volume->volume,flags);
 	if (xml==NULL) {
@@ -3338,6 +3351,10 @@ PHP_FUNCTION(libvirt_storagepool_get_xml_desc)
 	int retval = -1;
 
 	GET_STORAGEPOOL_FROM_ARGS("rs|l", &zpool, &xpath, &xpath_len, &flags);
+	if (xpath_len < 1)
+	{
+		xpath = NULL;
+	}
 
 	xml = virStoragePoolGetXMLDesc (pool->pool, flags);
 	if (xml == NULL)
@@ -4136,6 +4153,10 @@ PHP_FUNCTION(libvirt_nodedev_get_xml_desc)
 	int retval = -1;
 
 	GET_NODEDEV_FROM_ARGS("r|s",&znodedev,&xpath,&xpath_len);
+	if (xpath_len < 1)
+	{
+		xpath = NULL;
+	}
 
 	xml=virNodeDeviceGetXMLDesc(nodedev->device, 0);
 	if ( xml == NULL ) {
@@ -4576,6 +4597,10 @@ PHP_FUNCTION(libvirt_network_get_xml_desc)
 	int retval = -1;
 
 	GET_NETWORK_FROM_ARGS("r|s",&znetwork,&xpath,&xpath_len);
+	if (xpath_len < 1)
+	{
+		xpath = NULL;
+	}
 
 	xml=virNetworkGetXMLDesc(network->network, 0);
 
-- 
1.7.3.4
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]