Skip to content

Commit 3530faf

Browse files
author
Peter McCluskey
committed
64bit fixes, possible buffer overrun fixes
1 parent 6b167b3 commit 3530faf

File tree

5 files changed

+57
-23
lines changed

5 files changed

+57
-23
lines changed

Changelog

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
Version Changes for Hypermail
22
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Peter McCluskey (Oct 1, 2007)
4+
Changes from Fumihiro Kato to fix bugs on 64 bit systems and some
5+
possible buffer overflow problems.
6+
Change in rules about whether to escape urls; it now seems to escape them
7+
when found in the middle of the line the same way it has been doing when
8+
they are at the start of a line.
9+
10+
Peter McCluskey (Feb 16, 2007)
11+
Changes from Rick van der Zwet:
12+
cosmetic = tweaking the interface a small bit (right align, the message
13+
numbers, years in the date listing
14+
spamify-domain = obfuscate the body of the message as well (will also
15+
obfuscate 'ssh rick@foo.bar' this of course), moved the domain obfuscate
16+
yes/no to the general to make the function more portable
17+
Changes from Mike Fabian changing int to size_t.
18+
319
Peter McCluskey (Mar 27, 2006)
420
Add rel="nofollow" to text message URLs (option txtsuffix = 1).
521

src/parse.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -914,11 +914,12 @@ static char *mdecodeRFC2047(char *string, int length, char *charsetsave)
914914
/* base64 decoding */
915915
int len;
916916
#ifdef HAVE_ICONV
917+
size_t tmplen;
917918
char *output2;
918919
base64Decode(ptr, output, &len);
919-
output2=i18n_convstring(output,charset,"UTF-8",&len);
920-
memcpy(output,output2,len);
921-
output += len;
920+
output2=i18n_convstring(output,charset,"UTF-8",&tmplen);
921+
memcpy(output,output2,tmplen);
922+
output += tmplen;
922923
free(output2);
923924
memcpy(charsetsave,charset,strlen(charset)<255 ? strlen(charset) : 255 );
924925
#else

src/printfile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int printfile(FILE *fp, char *format, char *label, char *subject,
4646
register char *aptr;
4747
char c;
4848
char *ptr,*tmpptr=NULL;
49-
int tmplen;
49+
size_t tmplen;
5050

5151
aptr = format;
5252

src/string.c

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,20 @@ char *i18n_canonicalize_charset(char *cs){
100100
char *i18n_convstring(char *string, char *fromcharset, char *tocharset, size_t *len){
101101

102102
size_t origlen,strleft,bufleft;
103+
size_t origbuflen;
103104
char *convbuf,*origconvbuf;
104105
iconv_t iconvfd;
105106
size_t ret;
107+
int error;
106108

107109
if (string){
108110
strleft=origlen=strlen(string);
109111
}else{
110112
strleft=origlen=0;
111113
}
112-
origconvbuf=convbuf=malloc(origlen*7+1);
113-
memset(origconvbuf,0,origlen*7);
114+
origbuflen = origlen*7;
115+
origconvbuf=convbuf=malloc(origbuflen+1);
116+
memset(origconvbuf,0,origbuflen);
114117
bufleft=origlen*7;
115118

116119
if (!set_i18n || strcasecmp(fromcharset,tocharset)==0){
@@ -130,7 +133,7 @@ char *i18n_convstring(char *string, char *fromcharset, char *tocharset, size_t *
130133
printf("I18N: libiconv open error.\n");
131134
}
132135
}
133-
origlen=sprintf(origconvbuf,"(unknown charset) %s",string);
136+
origlen=snprintf(origconvbuf,origbuflen, "(unknown charset) %s",string);
134137
origconvbuf[origlen]=0x0;
135138
*len=origlen;
136139
return origconvbuf;
@@ -140,38 +143,51 @@ char *i18n_convstring(char *string, char *fromcharset, char *tocharset, size_t *
140143
iconv_close(iconvfd);
141144

142145
if (ret==(size_t)-1){
146+
error = 1;
143147
switch (errno){
144148
case E2BIG:
145149
if(set_showprogress){
146150
printf("I18N: buffer overflow.\n");
147151
}
152+
origlen=snprintf(origconvbuf, origbuflen,"(buffer overflow) %s",string);
153+
error = 1;
148154
break;
149155
case EILSEQ:
150156
if(set_showprogress){
151157
printf("I18N: invalid multibyte sequence, from %s to %s: %s.\n",fromcharset,tocharset,string);
152158
}
153-
origlen=sprintf(origconvbuf,"(wrong string) %s",string);
159+
origlen=snprintf(origconvbuf, origbuflen,"(wrong string) %s",string);
160+
error = 1;
154161
break;
155162
case EINVAL:
156163
if(set_showprogress){
157-
printf("I18N: incomplete multibyte sqeuence, from %s to %s: %s.\n",fromcharset,tocharset,string);
164+
printf("I18N: incomplete multibyte sequence, from %s to %s: %s.\n",fromcharset,tocharset,string);
158165
}
159-
origlen=sprintf(origconvbuf,"(wrong string) %s",string);
166+
origlen=snprintf(origconvbuf, origbuflen,"(wrong string) %s",string);
167+
error = 1;
160168
break;
161169
}
170+
} else {
171+
error = 0;
162172
}
163173

164-
/* hmm... do we really need to do this? (daigo) */
165-
if (strncasecmp(tocharset,"ISO-2022-JP",11)==0){
166-
*len=origlen*7-bufleft;
167-
*(origconvbuf+*len)=0x1b;
168-
*(origconvbuf+*len+1)=0x28;
169-
*(origconvbuf+*len+2)=0x42;
170-
*len+=3;
171-
}else{
172-
*len=origlen*7-bufleft;
174+
if (error) {
175+
origconvbuf[origlen]=0x0;
176+
*len=origlen;
177+
} else {
178+
/* hmm... do we really need to do this? (daigo) */
179+
if (strncasecmp(tocharset,"ISO-2022-JP",11)==0){
180+
*len=origlen*7-bufleft;
181+
*(origconvbuf+*len)=0x1b;
182+
*(origconvbuf+*len+1)=0x28;
183+
*(origconvbuf+*len+2)=0x42;
184+
*len+=3;
185+
}else{
186+
*len=origlen*7-bufleft;
187+
}
188+
189+
*(origconvbuf+*len)=0x0;
173190
}
174-
*(origconvbuf+*len)=0x0;
175191

176192
return origconvbuf;
177193
}
@@ -182,7 +198,7 @@ char *i18n_convstring(char *string, char *fromcharset, char *tocharset, size_t *
182198
char *i18n_utf2numref(char *instr,int escape){
183199

184200
char *ucs,*headofucs;
185-
int len;
201+
size_t len;
186202
struct Push buff;
187203
char strbuf[10];
188204

@@ -196,7 +212,8 @@ char *i18n_utf2numref(char *instr,int escape){
196212
headofucs=ucs=i18n_convstring(instr, "UTF-8", "UCS-2BE", &len);
197213

198214
unsigned int p;
199-
for(;len>0; len-=2){
215+
int i = (int) len;
216+
for(; i > 0; i-=2){
200217
p=(unsigned char)*ucs*256+(unsigned char)*(ucs+1);
201218
if (p<128){
202219
/* keep ASCII characters human readable */

src/uudecode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ int uudecode(FILE *input, /* get file data from (if needed) */
103103
}
104104

105105
n = DEC(*p);
106-
for (++p; n > 0; p += 4, n -= 3) {
106+
for (++p; (n > 0) && (outlen < 80); p += 4, n -= 3) {
107107
if (n >= 3) {
108108

109109
if (!(IS_DEC(*p) && IS_DEC(*(p + 1)) && IS_DEC(*(p + 2)) && IS_DEC(*(p + 3))))

0 commit comments

Comments
 (0)