Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 108451 | Differences between
and this patch

Collapse All | Expand All

(-)lynx2-8-5.orig/CHANGES (+5 lines)
Lines 1-6 Link Here
1
Changes since Lynx 2.8 release
1
Changes since Lynx 2.8 release
2
===============================================================================
2
===============================================================================
3
3
4
2005-0?-?? (2.8.5rel.1)
5
* eliminate fixed-size buffers in HTrjis() and related functions to avoid
6
  potential buffer overflow in nntp pages (report by Ulf Harnhammar). 
7
  Back-ported from Thomas Dickey's patch to 2.8.6dev.13 by Seemant Kulleen
8
4
2004-02-04 (2.8.5rel.1)
9
2004-02-04 (2.8.5rel.1)
5
* build fixes for MINGW32 -DK
10
* build fixes for MINGW32 -DK
6
* build fixes for OS/2 (reported by IZ) -TD
11
* build fixes for OS/2 (reported by IZ) -TD
(-)lynx2-8-5.orig/WWW/Library/Implementation/HTMIME.c (-31 / +48 lines)
Lines 2062-2076 Link Here
2062
**
2062
**
2063
**	Written by S. Ichikawa,
2063
**	Written by S. Ichikawa,
2064
**	partially inspired by encdec.c of <jh@efd.lth.se>.
2064
**	partially inspired by encdec.c of <jh@efd.lth.se>.
2065
**	Assume caller's buffer is LINE_LENGTH bytes, these decode to
2065
**	Caller's buffers decode to no longer than the input strings.
2066
**	no longer than the input strings.
2067
*/
2066
*/
2068
#define LINE_LENGTH 512		/* Maximum length of line of ARTICLE etc */
2069
#ifdef ESC
2070
#undef ESC
2071
#endif /* ESC */
2072
#include <LYCharVals.h>  /* S/390 -- gil -- 0163 */
2067
#include <LYCharVals.h>  /* S/390 -- gil -- 0163 */
2073
#define ESC	CH_ESC
2074
2068
2075
PRIVATE char HTmm64[] =
2069
PRIVATE char HTmm64[] =
2076
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" ;
2070
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" ;
Lines 2078-2088 Link Here
2078
PRIVATE int HTmmcont = 0;
2072
PRIVATE int HTmmcont = 0;
2079
2073
2080
PUBLIC void HTmmdec_base64 ARGS2(
2074
PUBLIC void HTmmdec_base64 ARGS2(
2081
	char *,		t,
2075
	char **,		t,
2082
	char *,		s)
2076
	char *,		s)
2083
{
2077
{
2084
    int   d, count, j, val;
2078
    int   d, count, j, val;
2085
    char  buf[LINE_LENGTH], *bp, nw[4], *p;
2079
    char  *buf, *bp, nw[4], *p;
2080
2081
	if ((buf = malloc(strlen(s) * 3 + 1)) == 0)
2082
		outofmem(__FILE__, "HTmmdec_base64");
2086
2083
2087
    for (bp = buf; *s; s += 4) {
2084
    for (bp = buf; *s; s += 4) {
2088
	val = 0;
2085
	val = 0;
Lines 2113-2126 Link Here
2113
	    *bp++ = nw[2];
2110
	    *bp++ = nw[2];
2114
    }
2111
    }
2115
    *bp = '\0';
2112
    *bp = '\0';
2116
    strcpy(t, buf);
2113
    StrAllocCopy(*t, buf);
2114
	FREE(buf);
2117
}
2115
}
2118
2116
2119
PUBLIC void HTmmdec_quote ARGS2(
2117
PUBLIC void HTmmdec_quote ARGS2(
2120
	char *,		t,
2118
	char **,		t,
2121
	char *,		s)
2119
	char *,		s)
2122
{
2120
{
2123
    char  buf[LINE_LENGTH], cval, *bp, *p;
2121
    char  *buf, cval, *bp, *p;
2122
2123
	if ((buf = malloc(strlen(s) + 1)) == 0)
2124
		outofmem(__FILE__, "HTmmdec_quote");
2124
2125
2125
    for (bp = buf; *s; ) {
2126
    for (bp = buf; *s; ) {
2126
	if (*s == '=') {
2127
	if (*s == '=') {
Lines 2147-2169 Link Here
2147
	}
2148
	}
2148
    }
2149
    }
2149
    *bp = '\0';
2150
    *bp = '\0';
2150
    strcpy(t, buf);
2151
    StrAllocCopy(*t, buf);
2152
	FREE(buf);
2151
}
2153
}
2152
2154
2153
/*
2155
/*
2154
**	HTmmdecode for ISO-2022-JP - FM
2156
**	HTmmdecode for ISO-2022-JP - FM
2155
*/
2157
*/
2156
PUBLIC void HTmmdecode ARGS2(
2158
PUBLIC void HTmmdecode ARGS2(
2157
	char *,		trg,
2159
	char **,		target,
2158
	char *,		str)
2160
	char *,		source)
2159
{
2161
{
2160
    char buf[LINE_LENGTH], mmbuf[LINE_LENGTH];
2162
    char *buf;
2163
	char *mmbuf = NULL;
2164
	char *m2buf = NULL;
2161
    char *s, *t, *u;
2165
    char *s, *t, *u;
2162
    int  base64, quote;
2166
    int  base64, quote;
2163
2167
2164
    buf[0] = '\0';
2168
    if ((buf = malloc(strlen(source) + 1)) == 0)
2169
		outofmem(__FILE__, "HTmmdecode");
2165
2170
2166
    for (s = str, u = buf; *s; ) {
2171
    for (s = source, u = buf; *s; ) {
2167
	if (!strncasecomp(s, "=?ISO-2022-JP?B?", 16)) {
2172
	if (!strncasecomp(s, "=?ISO-2022-JP?B?", 16)) {
2168
	    base64 = 1;
2173
	    base64 = 1;
2169
	} else {
2174
	} else {
Lines 2177-2191 Link Here
2177
	if (base64 || quote) {
2182
	if (base64 || quote) {
2178
	    if (HTmmcont) {
2183
	    if (HTmmcont) {
2179
		for (t = s - 1;
2184
		for (t = s - 1;
2180
		    t >= str && (*t == ' ' || *t == '\t'); t--) {
2185
		    t >= source && (*t == ' ' || *t == '\t'); t--) {
2181
			u--;
2186
			u--;
2182
		}
2187
		}
2183
	    }
2188
	    }
2189
		if (mmbuf == 0) /* allocate buffer big enough for source */
2190
			StrAllocCopy(mmbuf, source);
2184
	    for (s += 16, t = mmbuf; *s; ) {
2191
	    for (s += 16, t = mmbuf; *s; ) {
2185
		if (s[0] == '?' && s[1] == '=') {
2192
		if (s[0] == '?' && s[1] == '=') {
2186
		    break;
2193
		    break;
2187
		} else {
2194
		} else {
2188
		    *t++ = *s++;
2195
		    *t++ = *s++;
2196
			*t = '\0';
2189
		}
2197
		}
2190
	    }
2198
	    }
2191
	    if (s[0] != '?' || s[1] != '=') {
2199
	    if (s[0] != '?' || s[1] != '=') {
Lines 2195-2204 Link Here
2195
		*t = '\0';
2203
		*t = '\0';
2196
	    }
2204
	    }
2197
	    if (base64)
2205
	    if (base64)
2198
		HTmmdec_base64(mmbuf, mmbuf);
2206
		HTmmdec_base64(&m2buf, mmbuf);
2199
	    if (quote)
2207
	    if (quote)
2200
		HTmmdec_quote(mmbuf, mmbuf);
2208
		HTmmdec_quote(&m2buf, mmbuf);
2201
	    for (t = mmbuf; *t; )
2209
	    for (t = m2buf; *t; )
2202
		*u++ = *t++;
2210
		*u++ = *t++;
2203
	    HTmmcont = 1;
2211
	    HTmmcont = 1;
2204
	    /* if (*s == ' ' || *s == '\t') *u++ = *s; */
2212
	    /* if (*s == ' ' || *s == '\t') *u++ = *s; */
Lines 2211-2217 Link Here
2211
    }
2219
    }
2212
    *u = '\0';
2220
    *u = '\0';
2213
end:
2221
end:
2214
    strcpy(trg, buf);
2222
    StrAllocCopy(*target, buf);
2223
	FREE(m2buf);
2224
	FREE(mmbuf);
2225
	FREE(buf);
2215
}
2226
}
2216
2227
2217
/*
2228
/*
Lines 2219-2240 Link Here
2219
**  (The author of this function "rjis" is S. Ichikawa.)
2230
**  (The author of this function "rjis" is S. Ichikawa.)
2220
*/
2231
*/
2221
PUBLIC int HTrjis ARGS2(
2232
PUBLIC int HTrjis ARGS2(
2222
	char *,		t,
2233
	char **,	t,
2223
	char *,		s)
2234
	char *,		s)
2224
{
2235
{
2225
    char *p, buf[LINE_LENGTH];
2236
    char *p;
2237
	char *buf = NULL;
2226
    int kanji = 0;
2238
    int kanji = 0;
2227
2239
2228
    if (strchr(s, ESC) || !strchr(s, '$')) {
2240
    if (strchr(s, CH_ESC) || !strchr(s, '$')) {
2229
	if (s != t)
2241
	if (s != *t)
2230
	    strcpy(t, s);
2242
	    StrAllocCopy(*t, s);
2231
	return 1;
2243
	return 1;
2232
    }
2244
    }
2245
2246
	if ((buf = malloc(strlen(s) * 2 + 1)) == 0)
2247
		outofmem(__FILE__, "HTrjis");
2248
2233
    for (p = buf; *s; ) {
2249
    for (p = buf; *s; ) {
2234
	if (!kanji && s[0] == '$' && (s[1] == '@' || s[1] == 'B')) {
2250
	if (!kanji && s[0] == '$' && (s[1] == '@' || s[1] == 'B')) {
2235
	    if (HTmaybekanji((int)s[2], (int)s[3])) {
2251
	    if (HTmaybekanji((int)s[2], (int)s[3])) {
2236
		kanji = 1;
2252
		kanji = 1;
2237
		*p++ = ESC;
2253
		*p++ = CH_ESC;
2238
		*p++ = *s++;
2254
		*p++ = *s++;
2239
		*p++ = *s++;
2255
		*p++ = *s++;
2240
		*p++ = *s++;
2256
		*p++ = *s++;
Lines 2246-2252 Link Here
2246
	}
2262
	}
2247
	if (kanji && s[0] == '(' && (s[1] == 'J' || s[1] == 'B')) {
2263
	if (kanji && s[0] == '(' && (s[1] == 'J' || s[1] == 'B')) {
2248
	    kanji = 0;
2264
	    kanji = 0;
2249
	    *p++ = ESC;
2265
	    *p++ = CH_ESC;
2250
	    *p++ = *s++;
2266
	    *p++ = *s++;
2251
	    *p++ = *s++;
2267
	    *p++ = *s++;
2252
	    continue;
2268
	    continue;
Lines 2255-2261 Link Here
2255
    }
2271
    }
2256
    *p = *s;	/* terminate string */
2272
    *p = *s;	/* terminate string */
2257
2273
2258
    strcpy(t, buf);
2274
    StrAllocCopy(*t, buf);
2275
    FREE(buf);
2259
    return 0;
2276
    return 0;
2260
}
2277
}
2261
2278
(-)lynx2-8-5.orig/WWW/Library/Implementation/HTMIME.h (-12 / +4 lines)
Lines 67-87 Link Here
67
  For handling Japanese headers.
67
  For handling Japanese headers.
68
68
69
*/
69
*/
70
extern void HTmmdec_base64 PARAMS((
71
	char *	t,
72
	char *	s));
73
74
extern void HTmmdec_quote PARAMS((
75
	char *	t,
76
	char *	s));
77
78
extern void HTmmdecode PARAMS((
70
extern void HTmmdecode PARAMS((
79
	char *	trg,
71
	char **	target,
80
	char *	str));
72
	char *	source));
81
73
82
extern int HTrjis PARAMS((
74
extern int HTrjis PARAMS((
83
	char *	t,
75
	char **	target,
84
	char *	s));
76
	char *	source));
85
77
86
extern int HTmaybekanji PARAMS((
78
extern int HTmaybekanji PARAMS((
87
	int	c1,
79
	int	c1,
(-)lynx2-8-5.orig/WWW/Library/Implementation/HTNews.c (-61 / +22 lines)
Lines 940-946 Link Here
940
    }
940
    }
941
}
941
}
942
942
943
#ifdef SH_EX	/* for MIME */
944
#ifdef NEWS_DEBUG
943
#ifdef NEWS_DEBUG
945
/* for DEBUG 1997/11/07 (Fri) 17:20:16 */
944
/* for DEBUG 1997/11/07 (Fri) 17:20:16 */
946
void debug_print(unsigned char *p)
945
void debug_print(unsigned char *p)
Lines 962-1005 Link Here
962
}
961
}
963
#endif
962
#endif
964
963
965
static char *decode_mime(char *str)
964
static char *decode_mime(char **str)
966
{
965
{
967
    char temp[LINE_LENGTH];	/* FIXME: what determines the actual size? */
966
#ifdef SH_LEX
968
    char *p, *q;
969
970
    if (str == NULL)
971
	return "";
972
973
    if (HTCJK != JAPANESE)
967
    if (HTCJK != JAPANESE)
974
	return str;
968
		return *str;
975
976
    LYstrncpy(temp, str, sizeof(temp) - 1);
977
    q = temp;
978
    while ((p = strchr(q, '=')) != 0) {
979
	if (p[1] == '?') {
980
	    HTmmdecode(p, p);
981
	    q = p + 2;
982
	} else {
983
	    q = p + 1;
984
	}
985
    }
986
#ifdef NEWS_DEBUG
987
    printf("new=[");
988
    debug_print(temp);
989
#endif
969
#endif
990
    HTrjis(temp, temp);
970
	HTmmdecode(str, *str);
991
    strcpy(str, temp);
971
	return HTrjis(str, *str) ? *str : "";
992
993
    return str;
994
}
972
}
995
#else /* !SH_EX */
996
static char *decode_mime ARGS1(char *, str)
997
{
998
    HTmmdecode(str, str);
999
    HTrjis(str, str);
1000
    return str;
1001
}
1002
#endif
1003
973
1004
974
1005
/*	Read in an Article					read_article
975
/*	Read in an Article					read_article
Lines 1087-1108 Link Here
1087
1057
1088
		} else if (match(full_line, "SUBJECT:")) {
1058
		} else if (match(full_line, "SUBJECT:")) {
1089
		    StrAllocCopy(subject, HTStrip(strchr(full_line,':')+1));
1059
		    StrAllocCopy(subject, HTStrip(strchr(full_line,':')+1));
1090
		    decode_mime(subject);
1060
		    decode_mime(&subject);
1091
		} else if (match(full_line, "DATE:")) {
1061
		} else if (match(full_line, "DATE:")) {
1092
		    StrAllocCopy(date, HTStrip(strchr(full_line,':')+1));
1062
		    StrAllocCopy(date, HTStrip(strchr(full_line,':')+1));
1093
1063
1094
		} else if (match(full_line, "ORGANIZATION:")) {
1064
		} else if (match(full_line, "ORGANIZATION:")) {
1095
		    StrAllocCopy(organization,
1065
		    StrAllocCopy(organization,
1096
				 HTStrip(strchr(full_line,':')+1));
1066
				 HTStrip(strchr(full_line,':')+1));
1097
		    decode_mime(organization);
1067
		    decode_mime(&organization);
1098
1068
1099
		} else if (match(full_line, "FROM:")) {
1069
		} else if (match(full_line, "FROM:")) {
1100
		    StrAllocCopy(from, HTStrip(strchr(full_line,':')+1));
1070
		    StrAllocCopy(from, HTStrip(strchr(full_line,':')+1));
1101
		    decode_mime(from);
1071
		    decode_mime(&from);
1102
1072
1103
		} else if (match(full_line, "REPLY-TO:")) {
1073
		} else if (match(full_line, "REPLY-TO:")) {
1104
		    StrAllocCopy(replyto, HTStrip(strchr(full_line,':')+1));
1074
		    StrAllocCopy(replyto, HTStrip(strchr(full_line,':')+1));
1105
		    decode_mime(replyto);
1075
		    decode_mime(&replyto);
1106
1076
1107
		} else if (match(full_line, "NEWSGROUPS:")) {
1077
		} else if (match(full_line, "NEWSGROUPS:")) {
1108
		    StrAllocCopy(newsgroups, HTStrip(strchr(full_line,':')+1));
1078
		    StrAllocCopy(newsgroups, HTStrip(strchr(full_line,':')+1));
Lines 1711-1718 Link Here
1711
	int,		last_required)
1681
	int,		last_required)
1712
{
1682
{
1713
    char line[LINE_LENGTH+1];
1683
    char line[LINE_LENGTH+1];
1714
    char author[LINE_LENGTH+1];
1684
    char *author = NULL;
1715
    char subject[LINE_LENGTH+1];
1685
    char *subject = NULL;
1716
    char *date = NULL;
1686
    char *date = NULL;
1717
    int i;
1687
    int i;
1718
    char *p;
1688
    char *p;
Lines 1723-1731 Link Here
1723
    char *reference = NULL;		/* Href for article */
1693
    char *reference = NULL;		/* Href for article */
1724
    int art;				/* Article number WITHIN GROUP */
1694
    int art;				/* Article number WITHIN GROUP */
1725
    int status, count, first, last;	/* Response fields */
1695
    int status, count, first, last;	/* Response fields */
1726
					/* count is only an upper limit */
1727
1696
1728
    author[0] = '\0';
1729
    START(HTML_HEAD);
1697
    START(HTML_HEAD);
1730
    PUTC('\n');
1698
    PUTC('\n');
1731
    START(HTML_TITLE);
1699
    START(HTML_TITLE);
Lines 1946-1953 Link Here
1946
			case 'S':
1914
			case 'S':
1947
			case 's':
1915
			case 's':
1948
			    if (match(line, "SUBJECT:")) {
1916
			    if (match(line, "SUBJECT:")) {
1949
				LYstrncpy(subject, line+9, sizeof(subject)-1);/* Save subject */
1917
				StrAllocCopy(subject, line + 9);
1950
				decode_mime(subject);
1918
				decode_mime(&subject);
1951
			    }
1919
			    }
1952
			    break;
1920
			    break;
1953
1921
Lines 1964-1973 Link Here
1964
			case 'F':
1932
			case 'F':
1965
			    if (match(line, "FROM:")) {
1933
			    if (match(line, "FROM:")) {
1966
				char * p2;
1934
				char * p2;
1967
				LYstrncpy(author,
1935
				StrAllocCopy(author, strchr(line, ':') + 1);
1968
					author_name(strchr(line,':')+1),
1936
				decode_mime(&author);
1969
					sizeof(author)-1);
1970
				decode_mime(author);
1971
				p2 = author + strlen(author) - 1;
1937
				p2 = author + strlen(author) - 1;
1972
				if (*p2==LF)
1938
				if (*p2==LF)
1973
				    *p2 = '\0'; /* Chop off newline */
1939
				    *p2 = '\0'; /* Chop off newline */
Lines 1988-1998 Link Here
1988
1954
1989
		PUTC('\n');
1955
		PUTC('\n');
1990
		START(HTML_LI);
1956
		START(HTML_LI);
1991
#ifdef SH_EX	/* for MIME */
1957
		p = decode_mime(&subject);
1992
		HTSprintf0(&temp, "\"%s\"", decode_mime(subject));
1958
		HTSprintf0(&temp, "\"%s\"", NonNull(p));
1993
#else
1994
		HTSprintf0(&temp, "\"%s\"", subject);
1995
#endif
1996
		if (reference) {
1959
		if (reference) {
1997
		    write_anchor(temp, reference);
1960
		    write_anchor(temp, reference);
1998
		    FREE(reference);
1961
		    FREE(reference);
Lines 2001-2018 Link Here
2001
		}
1964
		}
2002
		FREE(temp);
1965
		FREE(temp);
2003
1966
2004
		if (author[0] != '\0') {
1967
		if (author != NULL) {
2005
		     PUTS(" - ");
1968
		     PUTS(" - ");
2006
		     if (LYListNewsDates)
1969
		     if (LYListNewsDates)
2007
			 START(HTML_I);
1970
			 START(HTML_I);
2008
#ifdef SH_EX	/* for MIME */
1971
		     PUTS(decode_mime(&author));
2009
		     PUTS(decode_mime(author));
2010
#else
2011
		     PUTS(author);
2012
#endif
2013
		     if (LYListNewsDates)
1972
		     if (LYListNewsDates)
2014
			 END(HTML_I);
1973
			 END(HTML_I);
2015
		     author[0] = '\0';
1974
		     FREE(author);
2016
		}
1975
		}
2017
		if (date) {
1976
		if (date) {
2018
		    if (!diagnostic) {
1977
		    if (!diagnostic) {
Lines 2055-2060 Link Here
2055
		MAYBE_END(HTML_LI);
2014
		MAYBE_END(HTML_LI);
2056
	    } /* Handle response to HEAD request */
2015
	    } /* Handle response to HEAD request */
2057
	} /* Loop over article */
2016
	} /* Loop over article */
2017
	FREE(author);
2018
	FREE(subject);
2058
    } /* If read headers */
2019
    } /* If read headers */
2059
    PUTC('\n');
2020
    PUTC('\n');
2060
    if (LYListNewsNumbers)
2021
    if (LYListNewsNumbers)

Return to bug 108451