Add type removed function wrappers to resolve UB of calling function through pointer to incorrect function type.
Unified · Split
| @@ -47,23 +47,37 @@ struct AVHMAC { · 46 unmodified lines | ||
| 47 | 47 | int keylen; |
| 48 | 48 | }; |
| 49 | 49 | |
| 50 | −#define DEFINE_SHA(bits) \ | |
| 51 | −static av_cold void sha ## bits ##_init(void *ctx) \ | |
| 50 | +#define DEFINE_ALGO_BITS_INIT(prefix, bits) \ | |
| 51 | +static av_cold void prefix##bits##_init(void *ctx) \ | |
| 52 | 52 | { \ |
| 53 | − av_sha_init(ctx, bits); \ | |
| 53 | + av_##prefix##_init(ctx, bits); \ | |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | −#define DEFINE_SHA512(bits) \ | |
| 57 | −static av_cold void sha ## bits ##_init(void *ctx) \ | |
| 58 | −{ \ | |
| 59 | − av_sha512_init(ctx, bits); \ | |
| 56 | +#define DEFINE_ALGO_INIT(prefix) \ | |
| 57 | +static av_cold void prefix##_init(void *ctx) \ | |
| 58 | +{ \ | |
| 59 | + av_##prefix##_init(ctx); \ | |
| 60 | +} | |
| 61 | + | |
| 62 | +#define DEFINE_ALGO(prefix) \ | |
| 63 | +static void prefix##_update(void *ctx, const uint8_t *src, size_t len) \ | |
| 64 | +{ \ | |
| 65 | + av_##prefix##_update(ctx, src, len); \ | |
| 66 | +} \ | |
| 67 | +static void prefix##_final(void *ctx, uint8_t *dst) \ | |
| 68 | +{ \ | |
| 69 | + av_##prefix##_final(ctx, dst); \ | |
| 60 | 70 | } |
| 61 | 71 | |
| 62 | −DEFINE_SHA(160) | |
| 63 | −DEFINE_SHA(224) | |
| 64 | −DEFINE_SHA(256) | |
| 65 | −DEFINE_SHA512(384) | |
| 66 | −DEFINE_SHA512(512) | |
| 72 | +DEFINE_ALGO_INIT(md5) | |
| 73 | +DEFINE_ALGO_BITS_INIT(sha, 160) | |
| 74 | +DEFINE_ALGO_BITS_INIT(sha, 224) | |
| 75 | +DEFINE_ALGO_BITS_INIT(sha, 256) | |
| 76 | +DEFINE_ALGO_BITS_INIT(sha512, 384) | |
| 77 | +DEFINE_ALGO_BITS_INIT(sha512, 512) | |
| 78 | +DEFINE_ALGO(md5) | |
| 79 | +DEFINE_ALGO(sha) | |
| 80 | +DEFINE_ALGO(sha512) | |
| 67 | 81 | |
| 68 | 82 | AVHMAC *av_hmac_alloc(enum AVHMACType type) |
| 69 | 83 | { |
| @@ -74,49 +88,49 @@ AVHMAC *av_hmac_alloc(enum AVHMACType type) · 4 unmodified lines | ||
| 74 | 88 | case AV_HMAC_MD5: |
| 75 | 89 | c->blocklen = 64; |
| 76 | 90 | c->hashlen = 16; |
| 77 | − c->init = (hmac_init) av_md5_init; | |
| 78 | − c->update = (hmac_update) av_md5_update; | |
| 79 | − c->final = (hmac_final) av_md5_final; | |
| 91 | + c->init = md5_init; | |
| 92 | + c->update = md5_update; | |
| 93 | + c->final = md5_final; | |
| 80 | 94 | c->hash = av_md5_alloc(); |
| 81 | 95 | break; |
| 82 | 96 | case AV_HMAC_SHA1: |
| 83 | 97 | c->blocklen = 64; |
| 84 | 98 | c->hashlen = 20; |
| 85 | 99 | c->init = sha160_init; |
| 86 | − c->update = (hmac_update) av_sha_update; | |
| 87 | − c->final = (hmac_final) av_sha_final; | |
| 100 | + c->update = sha_update; | |
| 101 | + c->final = sha_final; | |
| 88 | 102 | c->hash = av_sha_alloc(); |
| 89 | 103 | break; |
| 90 | 104 | case AV_HMAC_SHA224: |
| 91 | 105 | c->blocklen = 64; |
| 92 | 106 | c->hashlen = 28; |
| 93 | 107 | c->init = sha224_init; |
| 94 | − c->update = (hmac_update) av_sha_update; | |
| 95 | − c->final = (hmac_final) av_sha_final; | |
| 108 | + c->update = sha_update; | |
| 109 | + c->final = sha_final; | |
| 96 | 110 | c->hash = av_sha_alloc(); |
| 97 | 111 | break; |
| 98 | 112 | case AV_HMAC_SHA256: |
| 99 | 113 | c->blocklen = 64; |
| 100 | 114 | c->hashlen = 32; |
| 101 | 115 | c->init = sha256_init; |
| 102 | − c->update = (hmac_update) av_sha_update; | |
| 103 | − c->final = (hmac_final) av_sha_final; | |
| 116 | + c->update = sha_update; | |
| 117 | + c->final = sha_final; | |
| 104 | 118 | c->hash = av_sha_alloc(); |
| 105 | 119 | break; |
| 106 | 120 | case AV_HMAC_SHA384: |
| 107 | 121 | c->blocklen = 128; |
| 108 | 122 | c->hashlen = 48; |
| 109 | − c->init = sha384_init; | |
| 110 | − c->update = (hmac_update) av_sha512_update; | |
| 111 | − c->final = (hmac_final) av_sha512_final; | |
| 123 | + c->init = sha512384_init; | |
| 124 | + c->update = sha512_update; | |
| 125 | + c->final = sha512_final; | |
| 112 | 126 | c->hash = av_sha512_alloc(); |
| 113 | 127 | break; |
| 114 | 128 | case AV_HMAC_SHA512: |
| 115 | 129 | c->blocklen = 128; |
| 116 | 130 | c->hashlen = 64; |
| 117 | − c->init = sha512_init; | |
| 118 | − c->update = (hmac_update) av_sha512_update; | |
| 119 | − c->final = (hmac_final) av_sha512_final; | |
| 131 | + c->init = sha512512_init; | |
| 132 | + c->update = sha512_update; | |
| 133 | + c->final = sha512_final; | |
| 120 | 134 | c->hash = av_sha512_alloc(); |
| 121 | 135 | break; |
| 122 | 136 | default: |