]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Don't use zero terminated strings
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 14 Dec 2021 16:16:34 +0000 (16:16 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 14 Dec 2021 16:16:34 +0000 (16:16 +0000)
src/libutil/str_util.c
src/libutil/str_util.h

index 2d39ccf8ae67da2063444ed14f9855e14697f2e5..50af10f289293b6930718a965d0cf234772a2c42 100644 (file)
@@ -1571,18 +1571,18 @@ rspamd_strings_levenshtein_distance (const gchar *s1, gsize s1len,
 }
 
 GString *
-rspamd_header_value_fold (const gchar *name,
-               const gchar *value,
-               guint fold_max,
-               enum rspamd_newlines_type how,
-               const gchar *fold_on_chars)
+rspamd_header_value_fold (const gchar *name, gsize name_len,
+                                                 const gchar *value,
+                                                 gsize value_len,
+                                                 guint fold_max,
+                                                 enum rspamd_newlines_type how,
+                                                 const gchar *fold_on_chars)
 {
        GString *res;
        const guint default_fold_max = 76;
        guint cur_len;
-       const gchar *p, *c;
+       const gchar *p, *c, *end;
        guint nspaces = 0;
-       const gchar *last;
        gboolean first_token = TRUE;
        enum {
                fold_before = 0,
@@ -1603,14 +1603,15 @@ rspamd_header_value_fold (const gchar *name,
                fold_max = default_fold_max;
        }
 
-       res = g_string_sized_new (strlen (value));
+       res = g_string_sized_new (value_len);
 
        c = value;
        p = c;
+       end = value + value_len;
        /* name:<WSP> */
-       cur_len = strlen (name) + 2;
+       cur_len = name_len + 2;
 
-       while (*p) {
+       while (p < end) {
                switch (state) {
 
                case read_token:
@@ -1697,7 +1698,7 @@ rspamd_header_value_fold (const gchar *name,
                                         * Check any spaces that are appended to the result
                                         * before folding
                                         */
-                                       last = &res->str[res->len - 1];
+                                       const gchar *last = &res->str[res->len - 1];
 
                                        while (g_ascii_isspace (*last)) {
                                                last --;
index 47abf062ebf4976a1736ace8b56d0398a8081120..199a384cacbe9250c10d86484c890a496ac00b6d 100644 (file)
@@ -366,7 +366,9 @@ gint rspamd_strings_levenshtein_distance (const gchar *s1, gsize s1len,
  * @return new GString with the folded value
  */
 GString *rspamd_header_value_fold (const gchar *name,
+                                                                  gsize name_len,
                                                                   const gchar *value,
+                                                                  gsize value_len,
                                                                   guint fold_max,
                                                                   enum rspamd_newlines_type how,
                                                                   const gchar *fold_on_chars);