]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[crypto] Avoid an error when asn1_shrink() is already at end of object
authorMichael Brown <mcb30@ipxe.org>
Thu, 22 Mar 2012 02:10:17 +0000 (02:10 +0000)
committerMichael Brown <mcb30@ipxe.org>
Thu, 22 Mar 2012 02:28:49 +0000 (02:28 +0000)
asn1_skip() will return an error on reaching the end of an object, and
so should not be used as the basis for asn1_shrink().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/crypto/asn1.c

index cd502502d99b8d7cc387ec7a2c2b1fac3ca9bd05..2eab34223c03b6d4813306e98eb8004197f0b734 100644 (file)
@@ -220,16 +220,21 @@ int asn1_skip ( struct asn1_cursor *cursor, unsigned int type ) {
  * invalidated.
  */
 int asn1_shrink ( struct asn1_cursor *cursor, unsigned int type ) {
-       struct asn1_cursor next;
-       int rc;
+       struct asn1_cursor temp;
+       const void *end;
+       int len;
 
-       /* Skip to next object */
-       memcpy ( &next, cursor, sizeof ( next ) );
-       if ( ( rc = asn1_skip ( &next, type ) ) != 0 )
-               return rc;
+       /* Find end of object */
+       memcpy ( &temp, cursor, sizeof ( temp ) );
+       len = asn1_start ( &temp, type );
+       if ( len < 0 ) {
+               asn1_invalidate_cursor ( cursor );
+               return len;
+       }
+       end = ( temp.data + len );
 
        /* Shrink original cursor to contain only its first object */
-       cursor->len = ( next.data - cursor->data );
+       cursor->len = ( end - cursor->data );
 
        return 0;
 }