diff options
| author | Michael Brown | 2025-04-21 23:40:59 +0200 |
|---|---|---|
| committer | Michael Brown | 2025-04-22 00:30:13 +0200 |
| commit | 3f8937d2f3a82371022303c2e70369ce7a05f89e (patch) | |
| tree | 65bf2c954c2e5b9e483c7981cf02c4b609b5806f /src/crypto | |
| parent | [uaccess] Remove redundant read_user() (diff) | |
| download | ipxe-3f8937d2f3a82371022303c2e70369ce7a05f89e.tar.gz ipxe-3f8937d2f3a82371022303c2e70369ce7a05f89e.tar.xz ipxe-3f8937d2f3a82371022303c2e70369ce7a05f89e.zip | |
[crypto] Remove userptr_t from ASN.1 parsers
Simplify the ASN.1 code by assuming that all objects are fully
accessible via pointer dereferences. This allows the concept of
"additional data beyond the end of the cursor" to be removed, and
simplifies parsing of all ASN.1 image formats.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/crypto')
| -rw-r--r-- | src/crypto/asn1.c | 46 |
1 files changed, 11 insertions, 35 deletions
diff --git a/src/crypto/asn1.c b/src/crypto/asn1.c index aa57c6a8b..7b84f6fc3 100644 --- a/src/crypto/asn1.c +++ b/src/crypto/asn1.c @@ -88,7 +88,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * * @v cursor ASN.1 object cursor * @v type Expected type, or ASN1_ANY - * @v extra Additional length not present within partial cursor * @ret len Length of object body, or negative error * * The object cursor will be updated to point to the start of the @@ -100,8 +99,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * modified. If any other error occurs, the object cursor will be * invalidated. */ -static int asn1_start ( struct asn1_cursor *cursor, unsigned int type, - size_t extra ) { +static int asn1_start ( struct asn1_cursor *cursor, unsigned int type ) { unsigned int len_len; unsigned int len; @@ -145,9 +143,9 @@ static int asn1_start ( struct asn1_cursor *cursor, unsigned int type, cursor->data++; cursor->len--; } - if ( ( cursor->len + extra ) < len ) { + if ( cursor->len < len ) { DBGC ( cursor, "ASN1 %p bad length %d (max %zd)\n", - cursor, len, ( cursor->len + extra ) ); + cursor, len, cursor->len ); asn1_invalidate_cursor ( cursor ); return -EINVAL_ASN1_LEN; } @@ -156,34 +154,30 @@ static int asn1_start ( struct asn1_cursor *cursor, unsigned int type, } /** - * Enter ASN.1 partial object + * Enter ASN.1 object * * @v cursor ASN.1 object cursor * @v type Expected type, or ASN1_ANY - * @v extra Additional length beyond partial object * @ret rc Return status code * - * The object cursor and additional length will be updated to point to - * the body of the current ASN.1 object. + * The object cursor will be updated to point to the body of the + * current ASN.1 object. * * If any error occurs, the object cursor will be invalidated. */ -int asn1_enter_partial ( struct asn1_cursor *cursor, unsigned int type, - size_t *extra ) { +int asn1_enter ( struct asn1_cursor *cursor, unsigned int type ) { int len; /* Parse current object */ - len = asn1_start ( cursor, type, *extra ); + len = asn1_start ( cursor, type ); if ( len < 0 ) { asn1_invalidate_cursor ( cursor ); return len; } - /* Update cursor and additional length */ + /* Update cursor */ if ( ( ( size_t ) len ) <= cursor->len ) cursor->len = len; - assert ( ( len - cursor->len ) <= *extra ); - *extra = ( len - cursor->len ); DBGC ( cursor, "ASN1 %p entered object type %02x (len %x)\n", cursor, type, len ); @@ -191,24 +185,6 @@ int asn1_enter_partial ( struct asn1_cursor *cursor, unsigned int type, } /** - * Enter ASN.1 object - * - * @v cursor ASN.1 object cursor - * @v type Expected type, or ASN1_ANY - * @ret rc Return status code - * - * The object cursor will be updated to point to the body of the - * current ASN.1 object. - * - * If any error occurs, the object cursor will be invalidated. - */ -int asn1_enter ( struct asn1_cursor *cursor, unsigned int type ) { - static size_t no_extra = 0; - - return asn1_enter_partial ( cursor, type, &no_extra ); -} - -/** * Skip ASN.1 object if present * * @v cursor ASN.1 object cursor @@ -226,7 +202,7 @@ int asn1_skip_if_exists ( struct asn1_cursor *cursor, unsigned int type ) { int len; /* Parse current object */ - len = asn1_start ( cursor, type, 0 ); + len = asn1_start ( cursor, type ); if ( len < 0 ) return len; @@ -281,7 +257,7 @@ int asn1_shrink ( struct asn1_cursor *cursor, unsigned int type ) { /* Find end of object */ memcpy ( &temp, cursor, sizeof ( temp ) ); - len = asn1_start ( &temp, type, 0 ); + len = asn1_start ( &temp, type ); if ( len < 0 ) { asn1_invalidate_cursor ( cursor ); return len; |
