Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[crypto] Avoid an error when asn1_shrink() is already at end of object
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>
  • Loading branch information
mcb30 committed Mar 22, 2012
1 parent 2d9d0ad commit 2cd2447
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/crypto/asn1.c
Expand Up @@ -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;
}
Expand Down

0 comments on commit 2cd2447

Please sign in to comment.