]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix rubbish QP sequences decoding
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 20 Sep 2021 19:26:15 +0000 (20:26 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 20 Sep 2021 19:26:15 +0000 (20:26 +0100)
src/libutil/str_util.c

index 6b0cc3b6817c3b9bbb397841099f278278099746..fc53a8711c6f38da9b6f12faf29c1cf3d17099fa 100644 (file)
@@ -2427,9 +2427,15 @@ decode:
                        remain --;
                        ret = 0;
 
-                       if      (c >= '0' && c <= '9') { ret = c - '0'; }
-                       else if (c >= 'A' && c <= 'F') { ret = c - 'A' + 10; }
-                       else if (c >= 'a' && c <= 'f') { ret = c - 'a' + 10; }
+                       if (c >= '0' && c <= '9') {
+                               ret = c - '0';
+                       }
+                       else if (c >= 'A' && c <= 'F') {
+                               ret = c - 'A' + 10;
+                       }
+                       else if (c >= 'a' && c <= 'f') {
+                               ret = c - 'a' + 10;
+                       }
                        else if (c == '\r') {
                                /* Eat one more endline */
                                if (remain > 0 && *p == '\n') {
@@ -2445,9 +2451,13 @@ decode:
                        }
                        else {
                                /* Hack, hack, hack, treat =<garbadge> as =<garbadge> */
-                               if (remain > 0) {
+                               if (end - o > 1) {
+                                       *o++ = '=';
                                        *o++ = *(p - 1);
                                }
+                               else {
+                                       return (-1);
+                               }
 
                                continue;
                        }
@@ -2455,10 +2465,30 @@ decode:
                        if (remain > 0) {
                                c = *p++;
                                ret *= 16;
+                               remain --;
 
-                               if      (c >= '0' && c <= '9') { ret += c - '0'; }
-                               else if (c >= 'A' && c <= 'F') { ret += c - 'A' + 10; }
-                               else if (c >= 'a' && c <= 'f') { ret += c - 'a' + 10; }
+                               if (c >= '0' && c <= '9') {
+                                       ret += c - '0';
+                               }
+                               else if (c >= 'A' && c <= 'F') {
+                                       ret += c - 'A' + 10;
+                               }
+                               else if (c >= 'a' && c <= 'f') {
+                                       ret += c - 'a' + 10;
+                               }
+                               else {
+                                       /* Treat =<good><rubbish> as =<good><rubbish> */
+                                       if (end - o > 2) {
+                                               *o++ = '=';
+                                               *o++ = *(p - 2);
+                                               *o++ = *(p - 1);
+                                       }
+                                       else {
+                                               return (-1);
+                                       }
+
+                                       continue;
+                               }
 
                                if (end - o > 0) {
                                        *o++ = (gchar)ret;
@@ -2466,8 +2496,6 @@ decode:
                                else {
                                        return (-1);
                                }
-
-                               remain --;
                        }
                }
                else {