]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix entities decoding
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 21 Aug 2018 14:04:35 +0000 (15:04 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 21 Aug 2018 14:04:35 +0000 (15:04 +0100)
src/libserver/html.c
test/lua/unit/html.lua

index 4b100cc43b8a3edbddb1c5ec7d8d48f77c32aefb..79d4eebb38747f5cc6df83ba30e7a27bd0c91ed9 100644 (file)
@@ -338,6 +338,7 @@ rspamd_html_decode_entitles_inplace (gchar *s, guint len)
 {
        guint l, rep_len;
        gchar *t = s, *h = s, *e = s, *end_ptr;
+       const gchar *end;
        const gchar *entity;
        gint state = 0, val, base;
        khiter_t k;
@@ -349,6 +350,8 @@ rspamd_html_decode_entitles_inplace (gchar *s, guint len)
                l = len;
        }
 
+       end = s + l;
+
        while (h - s < (gint)l) {
                switch (state) {
                /* Out of entity */
@@ -379,13 +382,13 @@ rspamd_html_decode_entitles_inplace (gchar *s, guint len)
                                                if (kh_val (html_entity_by_name, k)) {
                                                        rep_len = strlen (kh_val (html_entity_by_name, k));
 
-                                                       if (end_ptr - t >= rep_len) {
+                                                       if (end - t >= rep_len) {
                                                                memcpy (t, kh_val (html_entity_by_name, k),
                                                                                rep_len);
                                                                t += rep_len;
                                                        }
                                                } else {
-                                                       if (end_ptr - t >= h - e) {
+                                                       if (end - t >= h - e) {
                                                                memmove (t, e, h - e);
                                                                t += h - e;
                                                        }
@@ -411,7 +414,7 @@ rspamd_html_decode_entitles_inplace (gchar *s, guint len)
 
                                        if (end_ptr != NULL && *end_ptr != '\0') {
                                                /* Skip undecoded */
-                                               if (end_ptr - t >= h - e) {
+                                               if (end - t >= h - e) {
                                                        memmove (t, e, h - e);
                                                        t += h - e;
                                                }
@@ -424,13 +427,13 @@ rspamd_html_decode_entitles_inplace (gchar *s, guint len)
                                                        if (kh_val (html_entity_by_number, k)) {
                                                                rep_len = strlen (kh_val (html_entity_by_number, k));
 
-                                                               if (end_ptr - t >= rep_len) {
+                                                               if (end - t >= rep_len) {
                                                                        memcpy (t, kh_val (html_entity_by_number, k),
                                                                                        rep_len);
                                                                        t += rep_len;
                                                                }
                                                        } else {
-                                                               if (end_ptr - t >= h - e) {
+                                                               if (end - t >= h - e) {
                                                                        memmove (t, e, h - e);
                                                                        t += h - e;
                                                                }
index a9a490e5b27fbb886006fcba04824876d6271ddc..68ee7d1eb74298aeb7cd7d3e716c6338f2e2840e 100644 (file)
@@ -121,7 +121,8 @@ context("HTML processing", function()
       local t = rspamd_util.parse_html(c[1])
 
       assert_not_nil(t)
-      assert_equal(c[2], tostring(t))
+      assert_equal(c[2], tostring(t), string.format("'%s' doesn't match with '%s'",
+          c[2], t))
     end
   end)
 end)