When wanting to compare the end of a string with another string, make
sure not to start somewhere before the start of the first string.
[extended tests]
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/7520)
size_t sz = strlen(alg);
static const char epilogue[] = " by EVP_PKEY";
- if (strcmp(alg + sz - (sizeof(epilogue) - 1), epilogue) == 0)
+ if (sz >= sizeof(epilogue)
+ && strcmp(alg + sz - (sizeof(epilogue) - 1), epilogue) == 0)
sz -= sizeof(epilogue) - 1;
if (strncmp(alg, "HMAC", sz) == 0) {