浏览代码

snmpstats: safety checks on hdr variable

Daniel-Constantin Mierla 7 年之前
父节点
当前提交
74c02fdb1c
共有 2 个文件被更改,包括 46 次插入36 次删除
  1. 22 17
      src/modules/snmpstats/snmpSIPRegUserLookupTable.c
  2. 24 19
      src/modules/snmpstats/snmpSIPStatusCodesTable.c

+ 22 - 17
src/modules/snmpstats/snmpSIPRegUserLookupTable.c

@@ -169,32 +169,35 @@ int kamailioSIPRegUserLookupTable_extract_index(
 	var_kamailioSIPRegUserLookupIndex.type = ASN_UNSIGNED;
 	var_kamailioSIPRegUserLookupIndex.next_variable = NULL;
 
+	if(hdr) {
+		/* parse the oid into the individual index components */
+		err = parse_oid_indexes(
+				hdr->oids, hdr->len, &var_kamailioSIPRegUserLookupIndex);
 
-	/* parse the oid into the individual index components */
-	err = parse_oid_indexes(
-			hdr->oids, hdr->len, &var_kamailioSIPRegUserLookupIndex);
-
-	if(err == SNMP_ERR_NOERROR) {
+		if(err == SNMP_ERR_NOERROR) {
 
-		/* copy index components into the context structure */
-		ctx->kamailioSIPRegUserLookupIndex =
-				*var_kamailioSIPRegUserLookupIndex.val.integer;
+			/* copy index components into the context structure */
+			ctx->kamailioSIPRegUserLookupIndex =
+					*var_kamailioSIPRegUserLookupIndex.val.integer;
 
-		/* 
+			/* 
 		 * Check to make sure that the index corresponds to the
 		 * global_userLookupCounter, as per the MIB specifications. 
 		 */
-		if(*var_kamailioSIPRegUserLookupIndex.val.integer
-						!= global_UserLookupCounter
-				|| *var_kamailioSIPRegUserLookupIndex.val.integer < 1) {
-			err = -1;
+			if(*var_kamailioSIPRegUserLookupIndex.val.integer
+							!= global_UserLookupCounter
+					|| *var_kamailioSIPRegUserLookupIndex.val.integer < 1) {
+				err = -1;
+			}
 		}
-	}
 
-	/* parsing may have allocated memory. free it. */
-	snmp_reset_var_buffers(&var_kamailioSIPRegUserLookupIndex);
+		/* parsing may have allocated memory. free it. */
+		snmp_reset_var_buffers(&var_kamailioSIPRegUserLookupIndex);
 
-	return err;
+		return err;
+	}
+
+	return -1;
 }
 
 /*
@@ -589,6 +592,8 @@ void kamailioSIPRegUserLookupTable_set_action(netsnmp_request_group *rg)
 	}
 #endif
 
+	LM_DBG("stage row_err = %d\n", row_err);
+
 	/*
 	 * check activation/deactivation
 	 */

+ 24 - 19
src/modules/snmpstats/snmpSIPStatusCodesTable.c

@@ -186,34 +186,37 @@ int kamailioSIPStatusCodesTable_extract_index(
 
 	var_kamailioSIPStatusCodeValue.next_variable = NULL;
 
-	/* parse the oid into the individual index components */
-	err = parse_oid_indexes(
-			hdr->oids, hdr->len, &var_kamailioSIPStatusCodeMethod);
+	if(hdr) {
+		/* parse the oid into the individual index components */
+		err = parse_oid_indexes(
+				hdr->oids, hdr->len, &var_kamailioSIPStatusCodeMethod);
 
-	if(err == SNMP_ERR_NOERROR) {
+		if(err == SNMP_ERR_NOERROR) {
 
-		/* copy index components into the context structure */
-		ctx->kamailioSIPStatusCodeMethod =
-				*var_kamailioSIPStatusCodeMethod.val.integer;
-		ctx->kamailioSIPStatusCodeValue =
-				*var_kamailioSIPStatusCodeValue.val.integer;
+			/* copy index components into the context structure */
+			ctx->kamailioSIPStatusCodeMethod =
+					*var_kamailioSIPStatusCodeMethod.val.integer;
+			ctx->kamailioSIPStatusCodeValue =
+					*var_kamailioSIPStatusCodeValue.val.integer;
 
 
-		if(*var_kamailioSIPStatusCodeMethod.val.integer < 1) {
-			err = -1;
-		}
+			if(*var_kamailioSIPStatusCodeMethod.val.integer < 1) {
+				err = -1;
+			}
 
-		if(*var_kamailioSIPStatusCodeValue.val.integer < 100
-				|| *var_kamailioSIPStatusCodeValue.val.integer > 699) {
-			err = -1;
+			if(*var_kamailioSIPStatusCodeValue.val.integer < 100
+					|| *var_kamailioSIPStatusCodeValue.val.integer > 699) {
+				err = -1;
+			}
 		}
-	}
 
+		/* parsing may have allocated memory. free it. */
+		snmp_reset_var_buffers(&var_kamailioSIPStatusCodeMethod);
 
-	/* parsing may have allocated memory. free it. */
-	snmp_reset_var_buffers(&var_kamailioSIPStatusCodeMethod);
+		return err;
+	}
 
-	return err;
+	return -1;
 }
 
 
@@ -561,6 +564,8 @@ void kamailioSIPStatusCodesTable_set_action(netsnmp_request_group *rg)
 	}
 #endif
 
+	LM_DBG("stage row_err = %d\n", row_err);
+
 	/*
 	 * check activation/deactivation
 	 */