summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/internal/man3/ossl_ends_with_dirsep.pod38
-rw-r--r--engines/e_loader_attic.c16
-rw-r--r--include/internal/cryptlib.h14
-rw-r--r--providers/implementations/storemgmt/file_store.c17
4 files changed, 55 insertions, 30 deletions
diff --git a/doc/internal/man3/ossl_ends_with_dirsep.pod b/doc/internal/man3/ossl_ends_with_dirsep.pod
new file mode 100644
index 0000000000..1924ab50f0
--- /dev/null
+++ b/doc/internal/man3/ossl_ends_with_dirsep.pod
@@ -0,0 +1,38 @@
+=pod
+
+=head1 NAME
+
+ossl_ends_with_dirsep - internal function to detect whether a path
+ends with directory separator
+
+=head1 SYNOPSIS
+
+ #include "internal/cryptlib.h"
+
+ int ossl_ends_with_dirsep(const char *path);
+
+=head1 DESCRIPTION
+
+ossl_ends_with_dirsep() detects whether the I<path> ends with a directory
+separator in platform agnostic way.
+
+=head1 RETURN VALUES
+
+ossl_ends_with_dirsep() returns 1 if the I<path> ends with a directory
+separator, 0 otherwise.
+
+=head1 HISTORY
+
+The function described here was added in OpenSSL 3.0.
+
+=head1 COPYRIGHT
+
+Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
+
+Licensed under the Apache License 2.0 (the "License"). You may not use
+this file except in compliance with the License. You can obtain a copy
+in the file LICENSE in the source distribution or at
+L<https://www.openssl.org/source/license.html>.
+
+=cut
+
diff --git a/engines/e_loader_attic.c b/engines/e_loader_attic.c
index 4f238b9cb2..176c159c8c 100644
--- a/engines/e_loader_attic.c
+++ b/engines/e_loader_attic.c
@@ -1424,27 +1424,13 @@ static int file_read_asn1(BIO *bp, unsigned char **data, long *len)
return 1;
}
-static int ends_with_dirsep(const char *uri)
-{
- if (*uri != '\0')
- uri += strlen(uri) - 1;
-#if defined(__VMS)
- if (*uri == ']' || *uri == '>' || *uri == ':')
- return 1;
-#elif defined(_WIN32)
- if (*uri == '\\')
- return 1;
-#endif
- return *uri == '/';
-}
-
static int file_name_to_uri(OSSL_STORE_LOADER_CTX *ctx, const char *name,
char **data)
{
assert(name != NULL);
assert(data != NULL);
{
- const char *pathsep = ends_with_dirsep(ctx->uri) ? "" : "/";
+ const char *pathsep = ossl_ends_with_dirsep(ctx->uri) ? "" : "/";
long calculated_length = strlen(ctx->uri) + strlen(pathsep)
+ strlen(name) + 1 /* \0 */;
diff --git a/include/internal/cryptlib.h b/include/internal/cryptlib.h
index e070618547..f1c6ddfd30 100644
--- a/include/internal/cryptlib.h
+++ b/include/internal/cryptlib.h
@@ -253,4 +253,18 @@ char *openssl_buf2hexstr_sep(const unsigned char *buf, long buflen, char sep);
unsigned char *openssl_hexstr2buf_sep(const char *str, long *buflen,
const char sep);
+static ossl_inline int ossl_ends_with_dirsep(const char *path)
+{
+ if (*path != '\0')
+ path += strlen(path) - 1;
+# if defined __VMS
+ if (*path == ']' || *path == '>' || *path == ':')
+ return 1;
+# elif defined _WIN32
+ if (*path == '\\')
+ return 1;
+# endif
+ return *path == '/';
+}
+
#endif
diff --git a/providers/implementations/storemgmt/file_store.c b/providers/implementations/storemgmt/file_store.c
index 3b6c50c9e5..5607f169cc 100644
--- a/providers/implementations/storemgmt/file_store.c
+++ b/providers/implementations/storemgmt/file_store.c
@@ -24,6 +24,7 @@
#include <openssl/params.h>
#include <openssl/decoder.h>
#include <openssl/store.h> /* The OSSL_STORE_INFO type numbers */
+#include "internal/cryptlib.h"
#include "internal/o_dir.h"
#include "crypto/pem.h" /* For PVK and "blob" PEM headers */
#include "crypto/decoder.h"
@@ -647,27 +648,13 @@ static int file_load_file(struct file_ctx_st *ctx,
* --------------------------------------
*/
-static int ends_with_dirsep(const char *uri)
-{
- if (*uri != '\0')
- uri += strlen(uri) - 1;
-#if defined(__VMS)
- if (*uri == ']' || *uri == '>' || *uri == ':')
- return 1;
-#elif defined(_WIN32)
- if (*uri == '\\')
- return 1;
-#endif
- return *uri == '/';
-}
-
static char *file_name_to_uri(struct file_ctx_st *ctx, const char *name)
{
char *data = NULL;
assert(name != NULL);
{
- const char *pathsep = ends_with_dirsep(ctx->uri) ? "" : "/";
+ const char *pathsep = ossl_ends_with_dirsep(ctx->uri) ? "" : "/";
long calculated_length = strlen(ctx->uri) + strlen(pathsep)
+ strlen(name) + 1 /* \0 */;