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 /crypto/asn1 | |
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 'crypto/asn1')
-rw-r--r-- | crypto/asn1/a_strnid.c | 6 | ||||
-rw-r--r-- | crypto/asn1/asn1_gen.c | 10 | ||||
-rw-r--r-- | crypto/asn1/asn_mime.c | 9 |
3 files changed, 10 insertions, 15 deletions
diff --git a/crypto/asn1/a_strnid.c b/crypto/asn1/a_strnid.c index 9e54db9292..2c6cb919f7 100644 --- a/crypto/asn1/a_strnid.c +++ b/crypto/asn1/a_strnid.c @@ -50,10 +50,10 @@ int ASN1_STRING_set_default_mask_asc(const char *p) unsigned long mask; char *end; - if (strncmp(p, "MASK:", 5) == 0) { - if (p[5] == '\0') + if (CHECK_AND_SKIP_PREFIX(p, "MASK:")) { + if (*p == '\0') return 0; - mask = strtoul(p + 5, &end, 0); + mask = strtoul(p, &end, 0); if (*end) return 0; } else if (strcmp(p, "nombstr") == 0) diff --git a/crypto/asn1/asn1_gen.c b/crypto/asn1/asn1_gen.c index ecff2be02e..bb0dcb2e09 100644 --- a/crypto/asn1/asn1_gen.c +++ b/crypto/asn1/asn1_gen.c @@ -325,13 +325,13 @@ static int asn1_cb(const char *elem, int len, void *bitstr) ERR_raise(ERR_LIB_ASN1, ASN1_R_UNKNOWN_FORMAT); return -1; } - if (strncmp(vstart, "ASCII", 5) == 0) + if (HAS_PREFIX(vstart, "ASCII")) arg->format = ASN1_GEN_FORMAT_ASCII; - else if (strncmp(vstart, "UTF8", 4) == 0) + else if (HAS_PREFIX(vstart, "UTF8")) arg->format = ASN1_GEN_FORMAT_UTF8; - else if (strncmp(vstart, "HEX", 3) == 0) + else if (HAS_PREFIX(vstart, "HEX")) arg->format = ASN1_GEN_FORMAT_HEX; - else if (strncmp(vstart, "BITLIST", 7) == 0) + else if (HAS_PREFIX(vstart, "BITLIST")) arg->format = ASN1_GEN_FORMAT_BITLIST; else { ERR_raise(ERR_LIB_ASN1, ASN1_R_UNKNOWN_FORMAT); @@ -765,7 +765,7 @@ static int mask_cb(const char *elem, int len, void *arg) int tag; if (elem == NULL) return 0; - if ((len == 3) && (strncmp(elem, "DIR", 3) == 0)) { + if (len == 3 && HAS_PREFIX(elem, "DIR")) { *pmask |= B_ASN1_DIRECTORYSTRING; return 1; } diff --git a/crypto/asn1/asn_mime.c b/crypto/asn1/asn_mime.c index 1b8ac34106..a05e485c47 100644 --- a/crypto/asn1/asn_mime.c +++ b/crypto/asn1/asn_mime.c @@ -972,13 +972,8 @@ static int mime_bound_check(char *line, int linelen, const char *bound, int blen if (blen + 2 > linelen) return 0; /* Check for part boundary */ - if ((strncmp(line, "--", 2) == 0) - && strncmp(line + 2, bound, blen) == 0) { - if (strncmp(line + blen + 2, "--", 2) == 0) - return 2; - else - return 1; - } + if ((CHECK_AND_SKIP_PREFIX(line, "--")) && strncmp(line, bound, blen) == 0) + return HAS_PREFIX(line + blen, "--") ? 2 : 1; return 0; } |