From c4218c88fe078570e7439c652a21f4773a432a76 Mon Sep 17 00:00:00 2001

From: Yann Ylavic <ylavic@apache.org>

Date: Tue, 10 Jun 2025 11:00:37 +0000

Subject: [PATCH] mod_session_dbd: set_cookie_name: ensure correct format



If args is an empty string, apr_strtok will return NULL and *last will never get set which results in a SIGSEGV in apr_isspace check



Submitted by: Thomas Meyer <thomas@m3y3r.de>



Github: closes #503





Follow-up to r1922931.



In set_cookie_name() and set_cookie_name2(), now that the empty 'name' argument is explicitly handled, the error message in check_string() can be simplified because the cookie name can't be empty anymore when this function is called.





Add a change entry to give credits to the author.





Merges r1922931, r1926188, r1926189 trunk

Submitted by: covener, jailletc36, jailletc36

Reviewed by: jailletc36, rpluem, ylavic





git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1926325 13f79535-47bb-0310-9956-ffa450edef68



Conflict:NA

Reference:https://github.com/apache/httpd/commit/c4218c88fe078570e7439c652a21f4773a432a76



---

 changes-entries/SessionDBDCookieName.txt |  3 +++

 modules/session/mod_session_dbd.c        | 12 +++++++++++-

 2 files changed, 14 insertions(+), 1 deletion(-)

 create mode 100644 changes-entries/SessionDBDCookieName.txt



diff --git a/changes-entries/SessionDBDCookieName.txt b/changes-entries/SessionDBDCookieName.txt

new file mode 100644

index 0000000..76c0aa1

--- /dev/null

+++ b/changes-entries/SessionDBDCookieName.txt

@@ -0,0 +1,3 @@

+  *) mod_session_dbd: ensure format used with SessionDBDCookieName and

+     SessionDBDCookieName2 are correct.

+     Github #503 [Thomas Meyer <thomas m3y3r.de>]

diff --git a/modules/session/mod_session_dbd.c b/modules/session/mod_session_dbd.c

index f683da2..65af937 100644

--- a/modules/session/mod_session_dbd.c

+++ b/modules/session/mod_session_dbd.c

@@ -537,7 +537,7 @@ static const char *check_string(cmd_parms * cmd, const char *string)

 {

     if (APR_SUCCESS != ap_cookie_check_string(string)) {

         return apr_pstrcat(cmd->pool, cmd->directive->directive,

-                           " cannot be empty, or contain '=', ';' or '&'.",

+                           " cannot contain '=', ';' or '&'.",

                            NULL);

     }

     return NULL;

@@ -571,6 +571,11 @@ static const char *set_cookie_name(cmd_parms * cmd, void *config, const char *ar

     char *line = apr_pstrdup(cmd->pool, args);

     session_dbd_dir_conf *conf = (session_dbd_dir_conf *) config;

     char *cookie = apr_strtok(line, " \t", &last);

+    if (!cookie) {

+        return apr_pstrcat(cmd->pool, cmd->directive->directive,

+                           " requires at least one argument!",

+                           NULL);

+    }

     conf->name = cookie;

     conf->name_set = 1;

     while (apr_isspace(*last)) {

@@ -586,6 +591,11 @@ static const char *set_cookie_name2(cmd_parms * cmd, void *config, const char *a

     char *line = apr_pstrdup(cmd->pool, args);

     session_dbd_dir_conf *conf = (session_dbd_dir_conf *) config;

     char *cookie = apr_strtok(line, " \t", &last);

+    if (!cookie) {

+        return apr_pstrcat(cmd->pool, cmd->directive->directive,

+                           " requires at least one argument!",

+                           NULL);

+    }

     conf->name2 = cookie;

     conf->name2_set = 1;

     while (apr_isspace(*last)) {

-- 

2.33.0