diff options
Diffstat (limited to 'include/mysql/service_encryption.h')
-rw-r--r-- | include/mysql/service_encryption.h | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/include/mysql/service_encryption.h b/include/mysql/service_encryption.h index 49639407..812b2861 100644 --- a/include/mysql/service_encryption.h +++ b/include/mysql/service_encryption.h @@ -36,6 +36,9 @@ #ifdef __cplusplus extern "C" { #endif +#ifndef MYSQL_ABI_CHECK +#include <assert.h> +#endif /* returned from encryption_key_get_latest_version() */ #define ENCRYPTION_KEY_VERSION_INVALID (~(unsigned int)0) @@ -101,6 +104,11 @@ static inline unsigned int encryption_key_version_exists(unsigned int id, unsign return encryption_key_get(id, version, NULL, &unused) != ENCRYPTION_KEY_VERSION_INVALID; } +/** main entrypoint to perform encryption or decryption + * @invariant `src` is valid for `slen` + * @invariant `dst` is valid for `*dlen`, `*dlen` is initialized + * @invariant `src` and `dst` do not overlap + */ static inline int encryption_crypt(const unsigned char* src, unsigned int slen, unsigned char* dst, unsigned int* dlen, const unsigned char* key, unsigned int klen, @@ -109,11 +117,23 @@ static inline int encryption_crypt(const unsigned char* src, unsigned int slen, { void *ctx= alloca(encryption_ctx_size(key_id, key_version)); int res1, res2; - unsigned int d1, d2; + unsigned int d1, d2= *dlen; + + // Verify dlen is initialized properly. See MDEV-30389 + assert(*dlen >= slen); + assert((dst[*dlen - 1]= 1)); + // Verify buffers do not overlap + if (src < dst) + assert(src + slen <= dst); + else + assert(dst + *dlen <= src); + if ((res1= encryption_ctx_init(ctx, key, klen, iv, ivlen, flags, key_id, key_version))) return res1; res1= encryption_ctx_update(ctx, src, slen, dst, &d1); + d2-= d1; res2= encryption_ctx_finish(ctx, dst + d1, &d2); + *dlen= d1 + d2; return res1 ? res1 : res2; } @@ -124,4 +144,3 @@ static inline int encryption_crypt(const unsigned char* src, unsigned int slen, #define MYSQL_SERVICE_ENCRYPTION_INCLUDED #endif - |