4a42e1
diff --git a/epan/dissectors/packet-coap.c b/epan/dissectors/packet-coap.c
4a42e1
index b37b6c231c..b7afe05f82 100644
4a42e1
--- a/epan/dissectors/packet-coap.c
4a42e1
+++ b/epan/dissectors/packet-coap.c
4a42e1
@@ -450,8 +450,11 @@ dissect_coap_opt_object_security(tvbuff_t *tvb, proto_item *head_item, proto_tre
4a42e1
 	coinfo->object_security = TRUE;
4a42e1
 
4a42e1
 	coinfo->oscore_info->piv = NULL;
4a42e1
+	coinfo->oscore_info->piv_len = 0;
4a42e1
 	coinfo->oscore_info->kid_context = NULL;
4a42e1
+	coinfo->oscore_info->kid_context_len = 0;
4a42e1
 	coinfo->oscore_info->kid = NULL;
4a42e1
+	coinfo->oscore_info->kid_len = 0;
4a42e1
 
4a42e1
 	if (opt_length == 0) { /* option length is zero, means flag byte is 0x00*/
4a42e1
 		/* add info to the head of the packet detail */
4a42e1
@@ -1144,11 +1147,9 @@ dissect_coap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* d
4a42e1
 							/* Indicate to OSCORE that this response contains its own PIV */
4a42e1
 							coinfo->oscore_info->piv_in_response = TRUE;
4a42e1
 							coap_trans->oscore_info->piv_in_response = TRUE;
4a42e1
-						} else {
4a42e1
-							if (coap_trans->oscore_info->piv) {
4a42e1
-								/* Use the PIV from the request */
4a42e1
-								coinfo->oscore_info->piv = (guint8 *) wmem_memdup(wmem_packet_scope(), coap_trans->oscore_info->piv, coap_trans->oscore_info->piv_len);
4a42e1
-							}
4a42e1
+						} else if (coap_trans->oscore_info->piv_len > 0) {
4a42e1
+							/* Use the PIV from the request */
4a42e1
+							coinfo->oscore_info->piv = (guint8 *) wmem_memdup(wmem_packet_scope(), coap_trans->oscore_info->piv, coap_trans->oscore_info->piv_len);
4a42e1
 							coinfo->oscore_info->piv_len = coap_trans->oscore_info->piv_len;
4a42e1
 						}
4a42e1
 						coinfo->oscore_info->response = TRUE;