[gnome-keyring/trust-store: 100/105] [egg] Produce proper messages for mismatched tags in DER parsing.



commit d3c93154d373db7d1e817140f8e787836a1a807f
Author: Stef Walter <stefw collabora co uk>
Date:   Sun Nov 21 03:06:00 2010 +0000

    [egg] Produce proper messages for mismatched tags in DER parsing.

 egg/egg-asn1x.c |   34 +++++++++++++++++++++-------------
 1 files changed, 21 insertions(+), 13 deletions(-)
---
diff --git a/egg/egg-asn1x.c b/egg/egg-asn1x.c
index c37acc8..34eb457 100644
--- a/egg/egg-asn1x.c
+++ b/egg/egg-asn1x.c
@@ -1069,6 +1069,20 @@ anode_decode_structured (GNode *node, Atlv *tlv, gint flags)
 }
 
 static gboolean
+anode_decode_option_or_default (GNode *node, Atlv *tlv, gint flags)
+{
+	if (flags & FLAG_OPTION || flags & FLAG_DEFAULT) {
+		tlv->len = 0;
+		tlv->end = tlv->buf;
+		tlv->off = 0;
+		anode_clr_tlv_data (node);
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+static gboolean
 anode_decode_anything_for_flags (GNode *node, Atlv *tlv, gint flags)
 {
 	gboolean ret;
@@ -1081,8 +1095,11 @@ anode_decode_anything_for_flags (GNode *node, Atlv *tlv, gint flags)
 		tag = tlv->tag;
 
 	/* Tag does not match, what do we do? */
-	if (tlv->off == 0 || tag != tlv->tag)
-		return FALSE;
+	if (tlv->off == 0 || tag != tlv->tag) {
+		if (anode_decode_option_or_default (node, tlv, flags))
+			return TRUE;
+		return anode_failure (node, "decoded tag did not match expected");
+	}
 
 	/* Structured value */
 	if (tlv->cls & ASN1_CLASS_STRUCTURED)
@@ -1100,17 +1117,8 @@ anode_decode_anything (GNode *node, Atlv *tlv)
 {
 	gint flags = anode_def_flags (node);
 
-	if (!anode_decode_anything_for_flags (node, tlv, flags)) {
-		if (flags & FLAG_OPTION || flags & FLAG_DEFAULT) {
-			tlv->len = 0;
-			tlv->end = tlv->buf;
-			tlv->off = 0;
-			anode_clr_tlv_data (node);
-			return TRUE;
-		}
-
-		return FALSE;
-	}
+	if (!anode_decode_anything_for_flags (node, tlv, flags))
+		return anode_decode_option_or_default (node, tlv, flags);
 
 	return TRUE;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]