Open
[sync] PR-24: fix CVE-2024-39929 #35
openeuler-ci-botAdd on May 11
[sync] PR-24: fix CVE-2024-39929 #35
Open
Total: 3 files changed+620-2
| @@ -0,0 +1,172 @@ | |||
| 1 | +From 6ce5c70cff8989418e05d01fd2a57703007a6357 Mon Sep 17 00:00:00 2001 | ||
| 2 | +From: Jeremy Harris <jgh146exb@wizmail.org> | ||
| 3 | +Date: Thu, 17 Oct 2024 11:47:59 +0800 | ||
| 4 | +Subject: [PATCH] Fix MIME parsing of filenames specified using multiple | ||
| 5 | + parameters. Bug 3099 | ||
| 6 | +--- | ||
| 7 | + doc/ChangeLog | 3 +++ | ||
| 8 | + doc/spec.txt | 10 +++++----- | ||
| 9 | + src/mime.c | 53 ++++++++++++++++++++++++++++----------------------- | ||
| 10 | + src/string.c | 1 + | ||
| 11 | + 4 files changed, 38 insertions(+), 29 deletions(-) | ||
| 12 | + | ||
| 13 | +diff --git a/doc/ChangeLog b/doc/ChangeLog | ||
| 14 | +index c88454c..635f408 100644 | ||
| 15 | +--- a/doc/ChangeLog | ||
| 16 | ++++ b/doc/ChangeLog | ||
| 17 | +@@ -221,6 +221,9 @@ JH/43 Bug 2903: avoid exit on an attempt to rewrite a malformed address. | ||
| 18 | + JH/44 Bug 3033: Harden dnsdb lookups against crafted DNS responses. | ||
| 19 | + CVE-2023-42219 | ||
| 20 | + | ||
| 21 | ++JH/45 Bug 3099: fix parsing of MIME filenames split over multiple paramemters. | ||
| 22 | ++ Previously the $mime_filename variable would have an incorrect value. | ||
| 23 | ++ | ||
| 24 | + HS/02 Fix string_is_ip_address() CVE-2023-42117 (Bug 3031) | ||
| 25 | + | ||
| 26 | + Exim version 4.96 | ||
| 27 | +diff --git a/doc/spec.txt b/doc/spec.txt | ||
| 28 | +index 6bb656e..8f598e7 100644 | ||
| 29 | +--- a/doc/spec.txt | ||
| 30 | ++++ b/doc/spec.txt | ||
| 31 | +@@ -32280,13 +32280,13 @@ The right hand side is expanded before use. After expansion, the value can be: | ||
| 32 | + the default path is then used. | ||
| 33 | + | ||
| 34 | + The decode condition normally succeeds. It is only false for syntax errors or | ||
| 35 | +-unusual circumstances such as memory shortages. You can easily decode a file | ||
| 36 | +-with its original, proposed filename using | ||
| 37 | ++errors or unusual circumstances such as memory shortages. | ||
| 38 | + | ||
| 39 | +-decode = $mime_filename | ||
| 40 | ++The variable &$mime_filename$& will have the suggested name for the file. | ||
| 41 | ++Note however that this might contain anything, and is very difficult | ||
| 42 | ++to safely use as all or even part of the filename. | ||
| 43 | + | ||
| 44 | +-However, you should keep in mind that $mime_filename might contain anything. If | ||
| 45 | +-you place files outside of the default path, they are not automatically | ||
| 46 | ++If you place files outside of the default path, they are not | ||
| 47 | + unlinked. | ||
| 48 | + | ||
| 49 | + For RFC822 attachments (these are messages attached to messages, with a | ||
| 50 | +diff --git a/src/mime.c b/src/mime.c | ||
| 51 | +index 975ddca..b11959c 100644 | ||
| 52 | +--- a/src/mime.c | ||
| 53 | ++++ b/src/mime.c | ||
| 54 | +@@ -587,10 +587,10 @@ while(1) | ||
| 55 | + | ||
| 56 | + while (*p) | ||
| 57 | + { | ||
| 58 | +- DEBUG(D_acl) debug_printf_indent("MIME: considering paramlist '%s'\n", p); | ||
| 59 | ++ DEBUG(D_acl) | ||
| 60 | ++ debug_printf_indent("MIME: considering paramlist '%s'\n", p); | ||
| 61 | + | ||
| 62 | +- if ( !mime_filename | ||
| 63 | +- && strncmpic(CUS"content-disposition:", header, 20) == 0 | ||
| 64 | ++ if ( strncmpic(CUS"content-disposition:", header, 20) == 0 | ||
| 65 | + && strncmpic(CUS"filename*", p, 9) == 0 | ||
| 66 | + ) | ||
| 67 | + { /* RFC 2231 filename */ | ||
| 68 | +@@ -604,12 +604,12 @@ while(1) | ||
| 69 | + | ||
| 70 | + if (q && *q) | ||
| 71 | + { | ||
| 72 | +- uschar * temp_string, * err_msg; | ||
| 73 | ++ uschar * temp_string, * err_msg, * fname = q; | ||
| 74 | + int slen; | ||
| 75 | + | ||
| 76 | + /* build up an un-decoded filename over successive | ||
| 77 | + filename*= parameters (for use when 2047 decode fails) */ | ||
| 78 | +- | ||
| 79 | ++/*XXX could grow a gstring here */ | ||
| 80 | + mime_fname_rfc2231 = string_sprintf("%#s%s", | ||
| 81 | + mime_fname_rfc2231, q); | ||
| 82 | + | ||
| 83 | +@@ -623,26 +623,31 @@ while(1) | ||
| 84 | + /* look for a ' in the "filename" */ | ||
| 85 | + while(*s != '\'' && *s) s++; /* s is 1st ' or NUL */ | ||
| 86 | + | ||
| 87 | +- if ((size = s-q) > 0) | ||
| 88 | +- mime_filename_charset = string_copyn(q, size); | ||
| 89 | +- | ||
| 90 | +- if (*(p = s)) p++; | ||
| 91 | +- while(*p == '\'') p++; /* p is after 2nd ' */ | ||
| 92 | ++ if (*s) /* there was a ' */ | ||
| 93 | ++ { | ||
| 94 | ++ if ((size = s-q) > 0) | ||
| 95 | ++ mime_filename_charset = string_copyn(q, size); | ||
| 96 | ++ if (*(fname = s)) fname++; | ||
| 97 | ++ while(*fname == '\'') fname++; /* fname is after 2nd ' */ | ||
| 98 | ++ } | ||
| 99 | + } | ||
| 100 | +- else | ||
| 101 | +- p = q; | ||
| 102 | + | ||
| 103 | +- DEBUG(D_acl) debug_printf_indent("MIME: charset %s fname '%s'\n", | ||
| 104 | +- mime_filename_charset ? mime_filename_charset : US"<NULL>", p); | ||
| 105 | ++ DEBUG(D_acl) | ||
| 106 | ++ debug_printf_indent("MIME: charset %s fname '%s'\n", | ||
| 107 | ++ mime_filename_charset ? mime_filename_charset : US"<NULL>", | ||
| 108 | ++ fname); | ||
| 109 | + | ||
| 110 | +- temp_string = rfc2231_to_2047(p, mime_filename_charset, &slen); | ||
| 111 | +- DEBUG(D_acl) debug_printf_indent("MIME: 2047-name %s\n", temp_string); | ||
| 112 | ++ temp_string = rfc2231_to_2047(fname, mime_filename_charset, | ||
| 113 | ++ &slen); | ||
| 114 | ++ DEBUG(D_acl) | ||
| 115 | ++ debug_printf_indent("MIME: 2047-name %s\n", temp_string); | ||
| 116 | + | ||
| 117 | + temp_string = rfc2047_decode(temp_string, FALSE, NULL, ' ', | ||
| 118 | +- NULL, &err_msg); | ||
| 119 | +- DEBUG(D_acl) debug_printf_indent("MIME: plain-name %s\n", temp_string); | ||
| 120 | ++ NULL, &err_msg); | ||
| 121 | ++ DEBUG(D_acl) | ||
| 122 | ++ debug_printf_indent("MIME: plain-name %s\n", temp_string); | ||
| 123 | + | ||
| 124 | +- if (!temp_string || (size = Ustrlen(temp_string)) == slen) | ||
| 125 | ++ if (!temp_string || (size = Ustrlen(temp_string)) == slen) | ||
| 126 | + decoding_failed = TRUE; | ||
| 127 | + else | ||
| 128 | + /* build up a decoded filename over successive | ||
| 129 | +@@ -651,9 +656,9 @@ while(1) | ||
| 130 | + mime_filename = mime_fname = mime_fname | ||
| 131 | + ? string_sprintf("%s%s", mime_fname, temp_string) | ||
| 132 | + : temp_string; | ||
| 133 | +- } | ||
| 134 | +- } | ||
| 135 | +- } | ||
| 136 | ++ } /*!decoding_failed*/ | ||
| 137 | ++ } /*q*/ | ||
| 138 | ++ } /*2231 filename*/ | ||
| 139 | + | ||
| 140 | + else | ||
| 141 | + /* look for interesting parameters */ | ||
| 142 | +@@ -682,7 +687,7 @@ while(1) | ||
| 143 | + | ||
| 144 | + | ||
| 145 | + /* There is something, but not one of our interesting parameters. | ||
| 146 | +- Advance past the next semicolon */ | ||
| 147 | ++ Advance past the next semicolon */ | ||
| 148 | + p = mime_next_semicolon(p); | ||
| 149 | + if (*p) p++; | ||
| 150 | + } /* param scan on line */ | ||
| 151 | +@@ -800,5 +805,5 @@ return rc; | ||
| 152 | + | ||
| 153 | + #endif /*WITH_CONTENT_SCAN*/ | ||
| 154 | + | ||
| 155 | +-/* vi: sw ai sw=2 | ||
| 156 | ++/* vi: aw ai sw=2 | ||
| 157 | + */ | ||
| 158 | +diff --git a/src/string.c b/src/string.c | ||
| 159 | +index dfe0f24..2f77cc7 100644 | ||
| 160 | +--- a/src/string.c | ||
| 161 | ++++ b/src/string.c | ||
| 162 | +@@ -1347,6 +1347,7 @@ Field width: decimal digits, or * | ||
| 163 | + Precision: dot, followed by decimal digits or * | ||
| 164 | + Length modifiers: h L l ll z | ||
| 165 | + Conversion specifiers: n d o u x X p f e E g G % c s S T Y D M | ||
| 166 | ++Alternate-form: %#s is silent about a null string | ||
| 167 | + | ||
| 168 | + Returns the possibly-new (if copy for growth or taint-handling was needed) | ||
| 169 | + string, not nul-terminated. | ||
| 170 | +-- | ||
| 171 | +2.43.0 | ||
| 172 | + | ||
Abackport-bug3099-MIME-support-RFC-2331-for-name.patch+440-0File content is under review, please try again later