diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2021-06-21 08:55:50 +0200 |
---|---|---|
committer | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2021-11-17 15:48:34 +0100 |
commit | 2ff286c26c29b69b02ca99656d26d2f8cfd54682 (patch) | |
tree | 71a01c51c47d0dd9528ff14357615d71420ba5a1 /ssl/ssl_rsa.c | |
parent | a6838c8d52087f2b0494bbab8486e10944aff7f7 (diff) |
Add and use HAS_PREFIX() and CHECK_AND_SKIP_PREFIX() for checking if string has literal prefix
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15847)
Diffstat (limited to 'ssl/ssl_rsa.c')
-rw-r--r-- | ssl/ssl_rsa.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/ssl/ssl_rsa.c b/ssl/ssl_rsa.c index cf410d6d87..5509389aa2 100644 --- a/ssl/ssl_rsa.c +++ b/ssl/ssl_rsa.c @@ -25,6 +25,9 @@ static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey); | SSL_EXT_TLS1_2_SERVER_HELLO \ | SSL_EXT_IGNORE_ON_RESUMPTION) +#define NAME_PREFIX1 "SERVERINFO FOR " +#define NAME_PREFIX2 "SERVERINFOV2 FOR " + int SSL_use_certificate(SSL *ssl, X509 *x) { int rv; @@ -760,8 +763,6 @@ int SSL_CTX_use_serverinfo_file(SSL_CTX *ctx, const char *file) long extension_length = 0; char *name = NULL; char *header = NULL; - static const char namePrefix1[] = "SERVERINFO FOR "; - static const char namePrefix2[] = "SERVERINFOV2 FOR "; unsigned int name_len; int ret = 0; BIO *bin = NULL; @@ -798,18 +799,18 @@ int SSL_CTX_use_serverinfo_file(SSL_CTX *ctx, const char *file) } /* Check that PEM name starts with "BEGIN SERVERINFO FOR " */ name_len = strlen(name); - if (name_len < sizeof(namePrefix1) - 1) { + if (name_len < sizeof(NAME_PREFIX1) - 1) { ERR_raise(ERR_LIB_SSL, SSL_R_PEM_NAME_TOO_SHORT); goto end; } - if (strncmp(name, namePrefix1, sizeof(namePrefix1) - 1) == 0) { + if (HAS_PREFIX(name, NAME_PREFIX1)) { version = SSL_SERVERINFOV1; } else { - if (name_len < sizeof(namePrefix2) - 1) { + if (name_len < sizeof(NAME_PREFIX2) - 1) { ERR_raise(ERR_LIB_SSL, SSL_R_PEM_NAME_TOO_SHORT); goto end; } - if (strncmp(name, namePrefix2, sizeof(namePrefix2) - 1) != 0) { + if (!HAS_PREFIX(name, NAME_PREFIX2)) { ERR_raise(ERR_LIB_SSL, SSL_R_PEM_NAME_BAD_PREFIX); goto end; } |