BUG/MINOR: pattern: a sample marked as const could be written
authorThierry Fournier <thierry.fournier@ozon.io>
Tue, 10 Nov 2020 19:51:36 +0000 (20:51 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 13 Nov 2020 15:50:32 +0000 (16:50 +0100)
The functions add final 0 to string if the final 0 is not set,
but don't check the flag CONST. This patch duplicates the strings
if the final zero is not set and the string is CONST.

Should be backported until 2.2 (at least)

(cherry picked from commit a68affeaa9377f88f773ef62a9bb2541dfb672d3)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 9633f444ac3ae540f6ce5dd0b0880fb40fabe9d5)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit b982485900e4f20f9c4a0ef2521da1c223acb30d)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/pattern.c

index 06773f5..fc228db 100644 (file)
@@ -465,11 +465,18 @@ struct pattern *pat_match_str(struct sample *smp, struct pattern_expr *expr, int
 
                if (smp->data.u.str.data < smp->data.u.str.size) {
                        /* we may have to force a trailing zero on the test pattern and
-                        * the buffer is large enough to accommodate it.
+                        * the buffer is large enough to accommodate it. If the flag
+                        * CONST is set, duplicate the string
                         */
                        prev = smp->data.u.str.area[smp->data.u.str.data];
-                       if (prev)
-                               smp->data.u.str.area[smp->data.u.str.data] = '\0';
+                       if (prev) {
+                               if (smp->flags & SMP_F_CONST) {
+                                       if (!smp_dup(smp))
+                                               return NULL;
+                               } else {
+                                       smp->data.u.str.area[smp->data.u.str.data] = '\0';
+                               }
+                       }
                }
                else {
                        /* Otherwise, the sample is duplicated. A trailing zero