vlib: additional runtime_data checks

Change-Id: I9b6ed9741fae89bdefa6f601398eb63a21155069
Signed-off-by: Damjan Marion <damarion@cisco.com>
diff --git a/src/vlib/threads.c b/src/vlib/threads.c
index 3756c3f..40789f5 100644
--- a/src/vlib/threads.c
+++ b/src/vlib/threads.c
@@ -681,9 +681,10 @@
 		vlib_node_t *n = vlib_get_node (vm, rt->node_index);
 		rt->cpu_index = vm_clone->cpu_index;
 		/* copy initial runtime_data from node */
-		if (n->runtime_data_bytes > 0)
+		if (n->runtime_data && n->runtime_data_bytes > 0)
 		  clib_memcpy (rt->runtime_data, n->runtime_data,
-			       VLIB_NODE_RUNTIME_DATA_SIZE);
+			       clib_min (VLIB_NODE_RUNTIME_DATA_SIZE,
+					 n->runtime_data_bytes));
 		else if (CLIB_DEBUG > 0)
 		  memset (rt->runtime_data, 0xfe,
 			  VLIB_NODE_RUNTIME_DATA_SIZE);
@@ -696,9 +697,10 @@
 		vlib_node_t *n = vlib_get_node (vm, rt->node_index);
 		rt->cpu_index = vm_clone->cpu_index;
 		/* copy initial runtime_data from node */
-		if (n->runtime_data_bytes > 0)
+		if (n->runtime_data && n->runtime_data_bytes > 0)
 		  clib_memcpy (rt->runtime_data, n->runtime_data,
-			       VLIB_NODE_RUNTIME_DATA_SIZE);
+			       clib_min (VLIB_NODE_RUNTIME_DATA_SIZE,
+					 n->runtime_data_bytes));
 		else if (CLIB_DEBUG > 0)
 		  memset (rt->runtime_data, 0xfe,
 			  VLIB_NODE_RUNTIME_DATA_SIZE);
@@ -961,8 +963,10 @@
 	vlib_node_t *n = vlib_get_node (vm, rt->node_index);
 	rt->cpu_index = vm_clone->cpu_index;
 	/* copy runtime_data, will be overwritten later for existing rt */
-	clib_memcpy (rt->runtime_data, n->runtime_data,
-		     VLIB_NODE_RUNTIME_DATA_SIZE);
+	if (n->runtime_data && n->runtime_data_bytes > 0)
+	  clib_memcpy (rt->runtime_data, n->runtime_data,
+		       clib_min (VLIB_NODE_RUNTIME_DATA_SIZE,
+				 n->runtime_data_bytes));
       }
 
       for (j = 0; j < vec_len (old_rt); j++)
@@ -985,8 +989,10 @@
 	vlib_node_t *n = vlib_get_node (vm, rt->node_index);
 	rt->cpu_index = vm_clone->cpu_index;
 	/* copy runtime_data, will be overwritten later for existing rt */
-	clib_memcpy (rt->runtime_data, n->runtime_data,
-		     VLIB_NODE_RUNTIME_DATA_SIZE);
+	if (n->runtime_data && n->runtime_data_bytes > 0)
+	  clib_memcpy (rt->runtime_data, n->runtime_data,
+		       clib_min (VLIB_NODE_RUNTIME_DATA_SIZE,
+				 n->runtime_data_bytes));
       }
 
       for (j = 0; j < vec_len (old_rt); j++)