Skip to content

Commit 44c1e08

Browse files
committed
Merge pull request #6 from Zentyal/ejhernandez/fix-memory-leak-when-non-decoding-quoted-printable
Fix memory leak when failing to parse a quoted printable
2 parents 8ce09d9 + 4ed6877 commit 44c1e08

File tree

2 files changed

+231
-30
lines changed

2 files changed

+231
-30
lines changed

ChangeLog

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,191 @@
1+
commit bb70653d820450507097230add9fa1fa13b2453c
2+
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
3+
Date: Thu Nov 20 09:42:42 2014 -0500
4+
5+
Revert "Fix crash when decoding a = at end of the data"
6+
7+
This reverts commit 1544d178c4cf56ee8358f06475c4b3e45dddc11c.
8+
9+
M sope-core/NGExtensions/NGQuotedPrintableCoding.m
10+
11+
commit 67c58bfd91e859c9bf643cf20cc44ed2fe6e389f
12+
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
13+
Date: Tue Nov 18 10:52:22 2014 -0500
14+
15+
Improved last commit after more Outlook's brain damange findings
16+
17+
M sope-core/NGExtensions/NGBase64Coding.m
18+
M sope-mime/NGMime/NGMimePartGenerator.m
19+
20+
commit c959d950a64d45d679f8a59a82a3b499c05415f8
21+
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
22+
Date: Tue Nov 18 09:06:37 2014 -0500
23+
24+
Disable original and broken padding.
25+
26+
M sope-core/NGExtensions/NGBase64Coding.m
27+
28+
commit 2c127ff4a7a448820c7b36b68918fce0c394c7d7
29+
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
30+
Date: Mon Nov 17 21:04:01 2014 -0500
31+
32+
Pad the output buffer to avoid Outlook corruption
33+
34+
M sope-core/NGExtensions/NGBase64Coding.m
35+
36+
commit 1544d178c4cf56ee8358f06475c4b3e45dddc11c
37+
Author: Enrique J. Hernández Blasco <ejhernandez@zentyal.com>
38+
Date: Fri Nov 14 11:37:04 2014 +0100
39+
40+
Fix crash when decoding a = at end of the data
41+
42+
In decoding a quoted printable mail. There is a buffer overflow
43+
as we are always parsing two bytes instead of one.
44+
45+
See the full backtrace at:
46+
47+
https://gist.github.com/sixstone-qq/cb8099b66c2911e8aaf2
48+
49+
M sope-core/NGExtensions/NGQuotedPrintableCoding.m
50+
51+
commit ceae95aaa2400b339c1ed42650c5bc35b2170dff
52+
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
53+
Date: Wed Nov 12 11:22:21 2014 -0500
54+
55+
Avoid failures on non-RHEL7 distros
56+
57+
M packaging/rhel/sope.spec
58+
59+
commit 31de3aac952b97c10b3fecbde5068673ee1538df
60+
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
61+
Date: Mon Nov 10 16:07:55 2014 -0500
62+
63+
Adjust the GNUstep makefiles path on EL7
64+
65+
M packaging/rhel/sope.spec
66+
67+
commit dd065c21ec420dbdbd486b9c57ccd33220eab123
68+
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
69+
Date: Mon Nov 10 15:38:24 2014 -0500
70+
71+
Cleaned up the file
72+
73+
M packaging/rhel/sope.spec
74+
75+
commit 7305bc339f72ba9790813ec66a8da53acaef4382
76+
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
77+
Date: Mon Nov 10 15:31:54 2014 -0500
78+
79+
Fixed spec file for EL7
80+
81+
M packaging/rhel/sope.spec
82+
83+
commit 19fbde18941a18037905086e46e20bb1f1c6206b
84+
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
85+
Date: Mon Nov 10 14:10:35 2014 -0500
86+
87+
Verbose logging
88+
89+
M packaging/rhel/sope.spec
90+
91+
commit 31aec7522fee85b7c164e0ffb49ab9cabe8303cd
92+
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
93+
Date: Mon Nov 10 14:02:05 2014 -0500
94+
95+
Fixed one more typo
96+
97+
M packaging/rhel/sope.spec
98+
99+
commit 6398402d19490a8f2ebf9c443adb3baa0b1df421
100+
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
101+
Date: Mon Nov 10 13:57:11 2014 -0500
102+
103+
Fixed typo
104+
105+
M packaging/rhel/sope.spec
106+
107+
commit 74a3367274565893a7d00753d38886b48ec3c096
108+
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
109+
Date: Mon Nov 10 13:51:33 2014 -0500
110+
111+
Improvements to spec file
112+
113+
M packaging/rhel/sope.spec
114+
115+
commit 7062f085c58b89daecb2b7db3ff782ebc4e47901
116+
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
117+
Date: Mon Nov 10 13:40:08 2014 -0500
118+
119+
spec file improvements, disabled Oracle support for now
120+
121+
M packaging/rhel/sope.spec
122+
123+
commit 75995d361fb0e5da74c9e84f753bc2dca03270c9
124+
Author: Wolfgang Sourdeau <Wolfgang@Contre.COM>
125+
Date: Sat Feb 22 09:00:47 2014 -0500
126+
127+
WOCompountElement: the array of children was not properly allocated, leading to a buffer overflow
128+
129+
M sope-appserver/NGObjWeb/DynamicElements/WOCompoundElement.h
130+
M sope-appserver/NGObjWeb/DynamicElements/WOCompoundElement.m
131+
132+
commit 9fe995c38d190f051acacdd5f2eeefc58b837f24
133+
Author: Jeroen Dekkers <jeroen@dekkers.ch>
134+
Date: Mon Oct 13 11:49:54 2014 +0200
135+
136+
Add support for arm64
137+
138+
M sope-gdl1/GDLAccess/EOSQLQualifier.m
139+
M sope-gdl1/GDLAccess/FoundationExt/PrintfFormatScanner.m
140+
141+
commit fb65ea6df85a76caaae3c480178d182c0cabe93c
142+
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
143+
Date: Wed Oct 15 16:21:51 2014 -0400
144+
145+
Small fix on RHEL7
146+
147+
M packaging/rhel/sope.spec
148+
149+
commit e193644086d96e0f4ca7ce13c9ca4bc4ba0c7d08
150+
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
151+
Date: Wed Oct 15 16:12:31 2014 -0400
152+
153+
Fixed unused dependancy
154+
155+
M packaging/rhel/sope.spec
156+
157+
commit bcffd9a6034ada60b20319e209cf4474b8f359f8
158+
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
159+
Date: Wed Oct 15 16:03:52 2014 -0400
160+
161+
Disabled Oracle support on RHEL7
162+
163+
M packaging/rhel/sope.spec
164+
165+
commit 00a3dc5c059d0efeb5003f768aca3c1ded0b3e66
166+
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
167+
Date: Wed Oct 15 15:50:29 2014 -0400
168+
169+
Initial work on RHEL 7
170+
171+
M packaging/rhel/sope.spec
172+
173+
commit cb31698b1b23a4a82cfa79a2e4f7b6c733c067ab
174+
Author: Francis Lachapelle <flachapelle@inverse.ca>
175+
Date: Mon Oct 6 13:54:11 2014 -0400
176+
177+
Fix BrazilianPortuguese language mapping
178+
179+
M sope-appserver/NGObjWeb/Languages.plist
180+
181+
commit 34893bd565e91c24dbed6c371ce57615345de6fd
182+
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
183+
Date: Fri Sep 26 14:34:25 2014 -0400
184+
185+
Update ChangeLog
186+
187+
M ChangeLog
188+
1189
commit 0ee64d0309ecc96a29d7c788e56246aec3606ad5
2190
Author: Ludovic Marcotte <lmarcotte@inverse.ca>
3191
Date: Mon Sep 15 15:46:45 2014 -0400

sope-core/NGExtensions/NGQuotedPrintableCoding.m

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ @implementation NSString(QuotedPrintableCoding)
2929

3030
- (NSString *)stringByDecodingQuotedPrintable {
3131
NSData *data;
32-
32+
3333
data = ([self length] > 0)
3434
? [self dataUsingEncoding:NSASCIIStringEncoding]
3535
: [NSData data];
36-
36+
3737
data = [data dataByDecodingQuotedPrintable];
38-
38+
3939
// TODO: should we default to some specific charset instead? (either
4040
// Latin1 or UTF-8
4141
// or the charset of the receiver?
@@ -44,14 +44,14 @@ - (NSString *)stringByDecodingQuotedPrintable {
4444

4545
- (NSString *)stringByEncodingQuotedPrintable {
4646
NSData *data;
47-
47+
4848
// TBD: which encoding to use?
4949
data = ([self length] > 0)
5050
? [self dataUsingEncoding:[NSString defaultCStringEncoding]]
5151
: [NSData data];
52-
52+
5353
data = [data dataByEncodingQuotedPrintable];
54-
54+
5555
return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]
5656
autorelease];
5757
}
@@ -65,31 +65,40 @@ - (NSData *)dataByDecodingQuotedPrintable {
6565
char *dest;
6666
size_t destSize;
6767
size_t resSize;
68-
68+
6969
destSize = [self length];
7070
dest = malloc(destSize * sizeof(char) + 2);
7171

72-
resSize =
72+
resSize =
7373
NGDecodeQuotedPrintableX([self bytes], [self length], dest, destSize, YES);
74-
75-
return ((int)resSize != -1)
76-
? [NSData dataWithBytesNoCopy:dest length:resSize]
77-
: nil;
74+
75+
if ((int)resSize == -1)
76+
{
77+
free(dest);
78+
return nil;
79+
}
80+
81+
return [NSData dataWithBytesNoCopy:dest length:resSize];
7882
}
83+
7984
- (NSData *)dataByDecodingQuotedPrintableTransferEncoding {
8085
char *dest;
8186
size_t destSize;
8287
size_t resSize;
83-
88+
8489
destSize = [self length];
8590
dest = malloc(destSize * sizeof(char) + 2);
8691

87-
resSize =
92+
resSize =
8893
NGDecodeQuotedPrintableX([self bytes], [self length], dest, destSize, NO);
89-
90-
return ((int)resSize != -1)
91-
? [NSData dataWithBytesNoCopy:dest length:resSize]
92-
: nil;
94+
95+
if ((int)resSize == -1)
96+
{
97+
free(dest);
98+
return nil;
99+
}
100+
101+
return [NSData dataWithBytesNoCopy:dest length:resSize];
93102
}
94103

95104
- (NSData *)dataByEncodingQuotedPrintable {
@@ -100,13 +109,17 @@ - (NSData *)dataByEncodingQuotedPrintable {
100109

101110
// length/64*3 should be plenty for soft newlines
102111
desLen = (length + length/64) *3;
103-
des = NGMallocAtomic(sizeof(char) * desLen);
112+
des = malloc(sizeof(char) * desLen);
104113

105114
desLen = NGEncodeQuotedPrintable(bytes, length, des, desLen);
106115

107-
return (int)desLen != -1
108-
? [NSData dataWithBytesNoCopy:des length:desLen]
109-
: nil;
116+
if ((int)desLen == -1)
117+
{
118+
free(des);
119+
return nil;
120+
}
121+
122+
return [NSData dataWithBytesNoCopy:des length:desLen];
110123
}
111124

112125
@end /* NSData(QuotedPrintableCoding) */
@@ -142,7 +155,7 @@ int NGDecodeQuotedPrintableX(const char *_src, unsigned _srcLen,
142155

143156
for (cnt = 0; ((cnt < _srcLen) && (destCnt < _destLen)); cnt++) {
144157
if (_src[cnt] != '=') {
145-
_dest[destCnt] =
158+
_dest[destCnt] =
146159
(_replaceUnderline && _src[cnt] == '_') ? 0x20 : _src[cnt];
147160
destCnt++;
148161
}
@@ -152,7 +165,7 @@ int NGDecodeQuotedPrintableX(const char *_src, unsigned _srcLen,
152165

153166
cnt++; // skip '='
154167
c1 = _src[cnt]; // first hex digit
155-
168+
156169
if (c1 == '\r' || c1 == '\n') {
157170
if (cnt < _srcLen && (_src[cnt + 1] == '\r' || _src[cnt + 1] == '\n' ))
158171
cnt++;
@@ -163,10 +176,10 @@ int NGDecodeQuotedPrintableX(const char *_src, unsigned _srcLen,
163176
break;
164177

165178
c1 = __hexToChar(c1);
166-
179+
167180
cnt++; // skip first hex digit
168181
c2 = __hexToChar(_src[cnt]);
169-
182+
170183
if ((c1 == -1) || (c2 == -1)) {
171184
if ((_destLen - destCnt) > 1) {
172185
_dest[destCnt] = _src[cnt - 1]; destCnt++;
@@ -181,7 +194,7 @@ int NGDecodeQuotedPrintableX(const char *_src, unsigned _srcLen,
181194
destCnt++;
182195
}
183196
}
184-
else
197+
else
185198
break;
186199
}
187200
}
@@ -204,7 +217,7 @@ int NGDecodeQuotedPrintable(const char *_src, unsigned _srcLen,
204217
...
205218
206219
In this encoding, octets are to be represented as determined by the
207-
following rules:
220+
following rules:
208221
209222
210223
(1) (General 8bit representation) Any octet, except a CR or
@@ -244,7 +257,7 @@ because some MTAs (Message Transport Agents, programs which transport
244257
are known to remove "white space" characters from the end of a line.
245258
Therefore, when decoding a Quoted-Printable body, any trailing white
246259
space on a line must be deleted, as it will necessarily have been
247-
added by intermediate transport agents.
260+
added by intermediate transport agents.
248261
249262
250263
(4) (Line Breaks) A line break in a text body, represented
@@ -269,7 +282,7 @@ represented by a (RFC 822) line break, which is also a
269282
encoded line indicates such a non-significant ("soft")
270283
line break in the encoded text.
271284
272-
*/
285+
*/
273286

274287
int NGEncodeQuotedPrintable(const char *_src, unsigned _srcLen,
275288
char *_dest, unsigned _destLen) {

0 commit comments

Comments
 (0)