[Openais] [PATCH] amf lib error when there are no csi attributes

angus salkeld angus.salkeld at alliedtelesis.co.nz
Tue Apr 17 22:15:29 PDT 2007


Hi

When you do not have any csi attribute defined then the call to set the component to a state of ACTIVE/STANDBY fails.

> because csi_descriptor.csiAttr.number == 0

This just checks before malloc'ing (and later free'ing)  the attributes.

Regards
Angus Salkeld
Allied Telesis Labs Limited

--- /home/anguss/projects/external/ais_clean/lib/amf.c  2007-04-11 11:35:54.000000000 +1200
+++ lib/amf.c   2007-04-18 16:59:43.000000000 +1200
@@ -310,6 +310,7 @@
 
 
                        SaAmfCSIDescriptorT csi_descriptor;
+                       SaAmfCSIAttributeT* csi_attribute_array;
 
                        csi_descriptor.csiFlags = res_lib_amf_csisetcallback->csiFlags;
                        memcpy(&csi_descriptor.csiName, &res_lib_amf_csisetcallback->csiName, 
@@ -317,34 +318,41 @@
                        csi_descriptor.csiStateDescriptor = res_lib_amf_csisetcallback->csiStateDescriptor;
                        csi_descriptor.csiAttr.number = res_lib_amf_csisetcallback->number;
 
-                       SaAmfCSIAttributeT* csi_attribute_array = malloc( sizeof( SaAmfCSIAttributeT ) * 
-                                                                         csi_descriptor.csiAttr.number );
 
-                       if( csi_attribute_array == 0) {
-                           return SA_AIS_ERR_LIBRARY;
-                       }
-                       csi_descriptor.csiAttr.attr = csi_attribute_array;
+                       if (csi_descriptor.csiAttr.number > 0) {
+                               csi_attribute_array = malloc( sizeof( SaAmfCSIAttributeT ) * 
+                                                                                         csi_descriptor.csiAttr.number );
+
+                               if( csi_attribute_array == NULL) {
+                                       return SA_AIS_ERR_LIBRARY;
+                               }
+
+                               char* p = res_lib_amf_csisetcallback->csi_attr_buf;
+                               int i;
 
-                       char* p = res_lib_amf_csisetcallback->csi_attr_buf;
-                       int i;
-
-                       for (i=0; i<csi_descriptor.csiAttr.number; i++) {
-                           csi_attribute_array[i].attrName = (SaUint8T*)p;
+                               for (i=0; i<csi_descriptor.csiAttr.number; i++) {
+                                       csi_attribute_array[i].attrName = (SaUint8T*)p;
 
-                           p += strlen(p) + 1;
-                           csi_attribute_array[i].attrValue = (SaUint8T*)p;
+                                       p += strlen(p) + 1;
+                                       csi_attribute_array[i].attrValue = (SaUint8T*)p;
 
-                           p += strlen(p) + 1;
+                                       p += strlen(p) + 1;
+
+                               } 
+                       } else {
+                               csi_attribute_array = NULL;
                        }
-
+                       csi_descriptor.csiAttr.attr = csi_attribute_array;
 
                        callbacks.saAmfCSISetCallback (
-                               res_lib_amf_csisetcallback->invocation,
-                               &res_lib_amf_csisetcallback->compName,
-                               res_lib_amf_csisetcallback->haState,
-                               &csi_descriptor);
+                                       res_lib_amf_csisetcallback->invocation,
+                                       &res_lib_amf_csisetcallback->compName,
+                                       res_lib_amf_csisetcallback->haState,
+                                       &csi_descriptor);
 
-                       free(csi_attribute_array);
+                       if (csi_attribute_array != NULL) {
+                               free(csi_attribute_array);
+                       }
                        break;
                    }
                case MESSAGE_RES_AMF_CSIREMOVECALLBACK:






More information about the Openais mailing list