Commit 5e53ea9531 for openssl.org
commit 5e53ea9531d09a5c805b8bb4ffe4ac8b9e810609
Author: Dr. David von Oheimb <dev@ddvo.net>
Date: Sat Apr 26 14:20:20 2025 +0200
ossl_store_register_loader_int(): refactor by extracting the macro OSSL_SKIP_SCHEME()
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
Reviewed-by: Simo Sorce <simo@redhat.com>
MergeDate: Thu Sep 10 13:32:55 2026
(Merged from https://github.com/openssl/openssl/pull/27507)
diff --git a/crypto/store/store_register.c b/crypto/store/store_register.c
index c9d789e27b..25f91c09f2 100644
--- a/crypto/store/store_register.c
+++ b/crypto/store/store_register.c
@@ -8,7 +8,6 @@
*/
#include <string.h>
-#include "crypto/ctype.h"
#include <assert.h>
#include <openssl/err.h>
@@ -165,12 +164,7 @@ int ossl_store_register_loader_int(OSSL_STORE_LOADER *loader)
*
* scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
*/
- if (ossl_isalpha(*scheme))
- while (*scheme != '\0'
- && (ossl_isalpha(*scheme)
- || ossl_isdigit(*scheme)
- || strchr("+-.", *scheme) != NULL))
- scheme++;
+ OSSL_SKIP_SCHEME(scheme);
if (*scheme != '\0') {
ERR_raise_data(ERR_LIB_OSSL_STORE, OSSL_STORE_R_INVALID_SCHEME,
"scheme=%s", loader->scheme);
diff --git a/include/internal/common.h b/include/internal/common.h
index d81a04333c..6834b595a5 100644
--- a/include/internal/common.h
+++ b/include/internal/common.h
@@ -13,6 +13,7 @@
#include <stdlib.h>
#include <string.h>
+#include "crypto/ctype.h"
#include "openssl/configuration.h"
#include "internal/e_os.h" /* ossl_inline in many files */
@@ -69,6 +70,13 @@ __owur static ossl_inline int ossl_assert_int(int expr, const char *exprstr,
(HAS_CASE_PREFIX(str, pre) ? ((str) += sizeof(pre) - 1, 1) : 0)
/* Check if the string literal |suffix| is a case-insensitive suffix of |str| */
#define HAS_CASE_SUFFIX(str, suffix) (strlen(str) < sizeof(suffix) - 1 ? 0 : OPENSSL_strcasecmp(str + strlen(str) - sizeof(suffix) + 1, suffix "") == 0)
+/* Advance string pointer past scheme acc to RFC 3986: ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) */
+#define OSSL_SKIP_SCHEME(s) \
+ do { \
+ if (ossl_isalpha(*(s))) \
+ while (*(s) != '\0' && (ossl_isalnum(*(s)) || strchr("+-.", *(s)) != NULL)) \
+ (s)++; \
+ } while (0)
/*
* Use this inside a union with the field that needs to be aligned to a