]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[rsa] Actually check the unused-bits byte in the public key bit string
authorMichael Brown <mcb30@ipxe.org>
Sun, 18 Mar 2012 20:42:03 +0000 (20:42 +0000)
committerMichael Brown <mcb30@ipxe.org>
Sun, 18 Mar 2012 20:46:38 +0000 (20:46 +0000)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/crypto/rsa.c

index a0bf39eb8a74f3e75af2457a1fa6cee2679c695c..6aa6e8971d7069b556472e6e5a05a9d41affa809 100644 (file)
@@ -236,12 +236,13 @@ static int rsa_init ( void *ctx, const void *key, size_t key_len ) {
 
                /* Check and skip unused-bits byte of bit string */
                bit_string = cursor.data;
-               if ( cursor.len < 1 ) {
+               if ( ( cursor.len < sizeof ( *bit_string ) ) ||
+                    ( bit_string->unused != 0 ) ) {
                        rc = -EINVAL;
                        goto err_parse;
                }
-               cursor.data++;
-               cursor.len--;
+               cursor.data = &bit_string->data;
+               cursor.len -= offsetof ( typeof ( *bit_string ), data );
 
                /* Enter RSAPublicKey */
                asn1_enter ( &cursor, ASN1_SEQUENCE );