浏览代码

Bug 611790 - fix coverify Defect Type: Null pointer dereferences issues 11940 - 12166

https://bugzilla.redhat.com/show_bug.cgi?id=611790
Resolves: bug 611790
Bug description: Fix coverify Defect Type: Null pointer dereferences issues 11940 - 12166
Fix description: Use the right pointer in LASIpAddPattern().
coverity ID: 11945
Noriko Hosoi 15 年之前
父节点
当前提交
a3c4404cf6
共有 1 个文件被更改,包括 12 次插入4 次删除
  1. 12 4
      lib/libaccess/lasip.cpp

+ 12 - 4
lib/libaccess/lasip.cpp

@@ -268,6 +268,10 @@ LASIpBuild(NSErr_t *errp, char *attr_name, CmpOp_t comparator, char *attr_patter
     char        *plusptr;
     char        *plusptr;
     int            retcode;
     int            retcode;
 
 
+    if (NULL == treetop) {
+        return ACL_RES_ERROR;
+    }
+
     /* ip address can be delimited by space, tab, comma, or carriage return
     /* ip address can be delimited by space, tab, comma, or carriage return
      * only.
      * only.
      */
      */
@@ -343,8 +347,12 @@ LASIpAddPattern(NSErr_t *errp, int netmask, int pattern, LASIpTree_t **treetop)
     LASIpTree_t    *curptr = NULL;    /* pointer to the current node    */
     LASIpTree_t    *curptr = NULL;    /* pointer to the current node    */
     LASIpTree_t    *newptr;
     LASIpTree_t    *newptr;
 
 
+    if (NULL == treetop) {
+        return ACL_RES_ERROR;
+    }
+
     /* stop at the first 1 in the netmask from low to high         */
     /* stop at the first 1 in the netmask from low to high         */
-    for (stopbit=0;  stopbit<32; stopbit++) {
+    for (stopbit=0; stopbit<32; stopbit++) {
         if ((netmask&(1<<stopbit)) != 0)
         if ((netmask&(1<<stopbit)) != 0)
             break;
             break;
     }
     }
@@ -353,7 +361,7 @@ LASIpAddPattern(NSErr_t *errp, int netmask, int pattern, LASIpTree_t **treetop)
     if (*treetop == (LASIpTree_t *)NULL) {    /* No tree at all */
     if (*treetop == (LASIpTree_t *)NULL) {    /* No tree at all */
         curptr = LASIpTreeAllocNode(errp);
         curptr = LASIpTreeAllocNode(errp);
         if (curptr == NULL) {
         if (curptr == NULL) {
-	    nserrGenerate(errp, ACLERRFAIL, ACLERR5100, ACL_Program, 1, XP_GetAdminStr(DBT_ipLasUnableToAllocateTreeNodeN_));
+            nserrGenerate(errp, ACLERRFAIL, ACLERR5100, ACL_Program, 1, XP_GetAdminStr(DBT_ipLasUnableToAllocateTreeNodeN_));
             return ACL_RES_ERROR;
             return ACL_RES_ERROR;
         }
         }
         *treetop = curptr;
         *treetop = curptr;
@@ -362,8 +370,8 @@ LASIpAddPattern(NSErr_t *errp, int netmask, int pattern, LASIpTree_t **treetop)
     /* Special case if the netmask is 0.
     /* Special case if the netmask is 0.
      */
      */
     if (stopbit > 31) {
     if (stopbit > 31) {
-        curptr->action[0] = (LASIpTree_t *)LAS_EVAL_TRUE;
-        curptr->action[1] = (LASIpTree_t *)LAS_EVAL_TRUE;
+        (*treetop)->action[0] = (LASIpTree_t *)LAS_EVAL_TRUE;
+        (*treetop)->action[1] = (LASIpTree_t *)LAS_EVAL_TRUE;
         return 0;
         return 0;
     }
     }