]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix SSL_new() with QUIC_server_method and improve formatting (Fixes #27255)
authorSamson S. Kolge <eglok1980@gmail.com>
Fri, 4 Apr 2025 11:38:22 +0000 (17:08 +0530)
committerNeil Horman <nhorman@openssl.org>
Sat, 5 Apr 2025 13:06:24 +0000 (09:06 -0400)
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27264)

ssl/quic/quic_impl.c
test/quicapitest.c

index 4e9b63b046d2c5b0d05b6794194e03f51ef45863..6e3de7d50501b1f56ad9109ce1c5bfbad4dd1e82 100644 (file)
@@ -561,6 +561,15 @@ SSL *ossl_quic_new(SSL_CTX *ctx)
     QUIC_CONNECTION *qc = NULL;
     SSL_CONNECTION *sc = NULL;
 
+    /*
+     * QUIC_server_method should not be used with SSL_new.
+     * It should only be used with SSL_new_listener.
+     */
+    if (ctx->method == OSSL_QUIC_server_method()) {
+        QUIC_RAISE_NON_NORMAL_ERROR(NULL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED, NULL);
+        return NULL;
+    }
+
     qc = OPENSSL_zalloc(sizeof(*qc));
     if (qc == NULL) {
         QUIC_RAISE_NON_NORMAL_ERROR(NULL, ERR_R_CRYPTO_LIB, NULL);
index 4782479cc6494431994a20f010f53e5e58484957..2e2692ae5f1a1591c78e739be629b2ebe0bd0311 100644 (file)
@@ -2654,10 +2654,43 @@ static int test_ssl_new_from_listener(void)
     return testresult;
 }
 
-/***********************************************************************************/
+static int test_server_method_with_ssl_new(void)
+{
+    SSL_CTX *ctx = NULL;
+    SSL *ssl = NULL;
+    int ret = 0;
+    unsigned long err;
+
+    /* Create a new SSL_CTX using the QUIC server method */
+    ctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_server_method());
+    if (!TEST_ptr(ctx))
+        goto end;
+
+    /* Try to create a new SSL object - this should fail */
+    ssl = SSL_new(ctx);
+
+    /* Check that SSL_new() returned NULL */
+    if (!TEST_ptr_null(ssl))
+        goto end;
 
+    /* Check for the expected error */
+    err = ERR_peek_error();
+    if (!TEST_true(ERR_GET_LIB(err) == ERR_LIB_SSL &&
+                   ERR_GET_REASON(err) == ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED))
+        goto end;
+
+    ret = 1;
+
+end:
+    SSL_free(ssl);
+    SSL_CTX_free(ctx);
+    return ret;
+}
+
+/***********************************************************************************/
 OPT_TEST_DECLARE_USAGE("provider config certsdir datadir\n")
 
+
 int setup_tests(void)
 {
     char *modulename;
@@ -2753,6 +2786,7 @@ int setup_tests(void)
 #ifndef OPENSSL_NO_SSL_TRACE
     ADD_TEST(test_new_token);
 #endif
+    ADD_TEST(test_server_method_with_ssl_new);
     return 1;
  err:
     cleanup_tests();