]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-auth: auth-digest - Rework auth_digest_parse_keyvalue() to yield const results
authorStephan Bosch <stephan.bosch@open-xchange.com>
Wed, 3 Sep 2025 21:31:26 +0000 (23:31 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Thu, 9 Oct 2025 08:41:22 +0000 (08:41 +0000)
src/lib-auth/auth-digest.c
src/lib-auth/auth-digest.h
src/lib-sasl/sasl-server-mech-digest-md5.c

index 575d02cffff4ed34508ffa45072347713aa60acc..5722b29df29d3bfff3cfbbc2c9ac96f13c7b83b0 100644 (file)
 /* Linear whitespace */
 #define IS_LWS(c) ((c) == ' ' || (c) == '\t')
 
-bool auth_digest_parse_keyvalue(char **data, char **key_r, char **value_r)
+bool auth_digest_parse_keyvalue(char **data, const char **key_r,
+                               const char **value_r)
 {
        /* @UNSAFE */
-       char *p, *dest;
+       char *p, *dest, *key, *value;
 
        p = *data;
        while (IS_LWS(*p)) p++;
 
        /* get key */
-       *key_r = p;
+       key = p;
        while (*p != '\0' && *p != '=' && *p != ',')
                p++;
 
@@ -31,7 +32,7 @@ bool auth_digest_parse_keyvalue(char **data, char **key_r, char **value_r)
                return FALSE;
        }
 
-       *value_r = p+1;
+       value = p+1;
 
        /* skip trailing whitespace in key */
        while (p > *data && IS_LWS(p[-1]))
@@ -39,7 +40,7 @@ bool auth_digest_parse_keyvalue(char **data, char **key_r, char **value_r)
        *p = '\0';
 
        /* get value */
-       p = *value_r;
+       p = value;
        while (IS_LWS(*p)) p++;
 
        if (*p != '"') {
@@ -55,7 +56,7 @@ bool auth_digest_parse_keyvalue(char **data, char **key_r, char **value_r)
                *p = '\0';
        } else {
                /* quoted string */
-               *value_r = dest = ++p;
+               value = dest = ++p;
                while (*p != '\0' && *p != '"') {
                        if (*p == '\\' && p[1] != '\0')
                                p++;
@@ -66,6 +67,8 @@ bool auth_digest_parse_keyvalue(char **data, char **key_r, char **value_r)
                *dest = '\0';
        }
 
+       *key_r = str_lcase(key);
+       *value_r = value;
        return TRUE;
 }
 
index 2ab4ab3640381e3da58c791e6f8aceb6b210b345..e579e65d93a7b84b5689947a981810722f49facc 100644 (file)
@@ -5,7 +5,8 @@
  * Parsing
  */
 
-bool auth_digest_parse_keyvalue(char **data, char **key_r, char **value_r);
+bool auth_digest_parse_keyvalue(char **data, const char **key_r,
+                               const char **value_r);
 
 /*
  * Processing
index 75043f1e24ab246da3d4d24ebcc1d9f629348a9f..1436d7412e1b89403a1bc1092ba862afca62498c 100644 (file)
@@ -189,13 +189,11 @@ verify_credentials(struct sasl_server_mech_request *auth_request,
 
 static bool
 auth_handle_response(struct digest_auth_request *request,
-                    char *key, char *value, const char **error_r)
+                    const char *key, const char *value, const char **error_r)
 {
        struct sasl_server_mech_request *auth_request = &request->auth_request;
        unsigned int i;
 
-       (void)str_lcase(key);
-
        if (strcmp(key, "realm") == 0) {
                if (auth_request->realm == NULL && *value != '\0')
                        sasl_server_request_set_realm(auth_request, value);
@@ -367,7 +365,7 @@ parse_digest_response(struct digest_auth_request *request,
                      const char **error_r)
 {
        struct sasl_server_mech_request *auth_request = &request->auth_request;
-       char *copy, *key, *value;
+       char *copy;
        bool failed;
 
        /*
@@ -397,6 +395,8 @@ parse_digest_response(struct digest_auth_request *request,
           potential problems with NUL characters in strings. */
        copy = t_strdup_noconst(t_strndup(data, size));
        while (*copy != '\0') {
+               const char *key, *value;
+
                if (auth_digest_parse_keyvalue(&copy, &key, &value)) {
                        if (!auth_handle_response(request, key, value,
                                                  error_r)) {