Browse Source

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: Catch possible NULL pointer in age_str2time().
Endi S. Dewata 15 years ago
parent
commit
ecaf325734
1 changed files with 11 additions and 4 deletions
  1. 11 4
      ldap/servers/plugins/retrocl/retrocl_trim.c

+ 11 - 4
ldap/servers/plugins/retrocl/retrocl_trim.c

@@ -441,12 +441,16 @@ age_str2time (const char *age)
     }
     }
     
     
     maxage = slapi_ch_strdup ( age );
     maxage = slapi_ch_strdup ( age );
+    if (!maxage) {
+        slapi_log_error( SLAPI_LOG_PLUGIN, "retrocl",
+		       "age_str2time: Out of memory\n" );
+        ageval = -1;
+        goto done;
+    }
+
     unit = maxage[ strlen( maxage ) - 1 ];
     unit = maxage[ strlen( maxage ) - 1 ];
     maxage[ strlen( maxage ) - 1 ] = '\0';
     maxage[ strlen( maxage ) - 1 ] = '\0';
     ageval = strntoul( maxage, strlen( maxage ), 10 );
     ageval = strntoul( maxage, strlen( maxage ), 10 );
-    if ( maxage) {
-        slapi_ch_free ( (void **) &maxage );
-    }
     switch ( unit ) {
     switch ( unit ) {
     case 's':
     case 's':
       break;
       break;
@@ -468,7 +472,10 @@ age_str2time (const char *age)
 		       "for maxiumum changelog age\n", unit );
 		       "for maxiumum changelog age\n", unit );
       ageval = -1;
       ageval = -1;
     }
     }
-    
+done:
+    if ( maxage) {
+        slapi_ch_free ( (void **) &maxage );
+    }
     return ageval;
     return ageval;
 }
 }