diff options
author | Pauli <paul.dale@oracle.com> | 2017-09-12 09:13:12 +1000 |
---|---|---|
committer | Pauli <paul.dale@oracle.com> | 2017-09-14 10:26:54 +1000 |
commit | 582e2ed2718bd367e747cb9077d2044cf51cc9a4 (patch) | |
tree | b5679fdc099abd78df8731f18a55fe08d51d0fdf /crypto | |
parent | 4cacc9d510c20368d13dcaf2c95c25d6d1ceef6c (diff) |
Revert "Reuse strndup(), simplify code"
This reverts commit 1caaea133873d549fa52fbf265298d2d35442477.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4357)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/x509/by_dir.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/crypto/x509/by_dir.c b/crypto/x509/by_dir.c index 8476f0025e..e1a09cb0dd 100644 --- a/crypto/x509/by_dir.c +++ b/crypto/x509/by_dir.c @@ -150,7 +150,8 @@ static void free_dir(X509_LOOKUP *lu) static int add_cert_dir(BY_DIR *ctx, const char *dir, int type) { - const char *s, *p; + int j, len; + const char *s, *ss, *p; if (dir == NULL || !*dir) { X509err(X509_F_ADD_CERT_DIR, X509_R_INVALID_DIRECTORY); @@ -162,17 +163,15 @@ static int add_cert_dir(BY_DIR *ctx, const char *dir, int type) do { if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0')) { BY_DIR_ENTRY *ent; - int j; - size_t len; - const char *ss = s; + ss = s; s = p + 1; - len = p - ss; + len = (int)(p - ss); if (len == 0) continue; for (j = 0; j < sk_BY_DIR_ENTRY_num(ctx->dirs); j++) { ent = sk_BY_DIR_ENTRY_value(ctx->dirs, j); - if (strlen(ent->dir) == len && - strncmp(ent->dir, ss, len) == 0) + if (strlen(ent->dir) == (size_t)len && + strncmp(ent->dir, ss, (unsigned int)len) == 0) break; } if (j < sk_BY_DIR_ENTRY_num(ctx->dirs)) @@ -189,11 +188,13 @@ static int add_cert_dir(BY_DIR *ctx, const char *dir, int type) return 0; ent->dir_type = type; ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp); - ent->dir = OPENSSL_strndup(ss, len); + ent->dir = OPENSSL_malloc((unsigned int)len + 1); if (ent->dir == NULL || ent->hashes == NULL) { by_dir_entry_free(ent); return 0; } + strncpy(ent->dir, ss, (unsigned int)len); + ent->dir[len] = '\0'; if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) { by_dir_entry_free(ent); return 0; |