View | Details | Raw Unified | Return to bug 85842
Collapse All | Expand All

(-)./src/http/client/OW_HTTPClient.cpp.orig (-2 / +2 lines)
Lines 922-929 Link Here
922
	}
922
	}
923
	else if (headerHasKey("Content-Length"))
923
	else if (headerHasKey("Content-Length"))
924
	{
924
	{
925
		rval = new HTTPLenLimitIStream(m_istr,
925
		UInt64 clen = getHeaderValue("Content-Length").toUInt64(); 
926
			getHeaderValue("Content-Length").toInt32());
926
		rval = new HTTPLenLimitIStream(m_istr,clen); 
927
	}
927
	}
928
	if (getHeaderValue("Content-Encoding").equalsIgnoreCase("deflate"))
928
	if (getHeaderValue("Content-Encoding").equalsIgnoreCase("deflate"))
929
	{
929
	{
(-)./src/http/common/OW_HTTPChunkedIStream.cpp.orig (-12 / +13 lines)
Lines 48-54 Link Here
48
HTTPChunkedIStreamBuffer::HTTPChunkedIStreamBuffer(istream& istr,
48
HTTPChunkedIStreamBuffer::HTTPChunkedIStreamBuffer(istream& istr,
49
	HTTPChunkedIStream* chunker)
49
	HTTPChunkedIStream* chunker)
50
	: BaseStreamBuffer(HTTP_BUF_SIZE, "in"), m_istr(istr),
50
	: BaseStreamBuffer(HTTP_BUF_SIZE, "in"), m_istr(istr),
51
	m_inLen(-1), m_inPos(0), m_isEOF(false), m_pChunker(chunker)
51
	m_inLen(0), m_inPos(0), m_isEOF(false), m_pChunker(chunker)
52
{
52
{
53
}
53
}
54
//////////////////////////////////////////////////////////////////////////////
54
//////////////////////////////////////////////////////////////////////////////
Lines 59-74 Link Here
59
int
59
int
60
HTTPChunkedIStreamBuffer::buffer_from_device(char* c, int n)
60
HTTPChunkedIStreamBuffer::buffer_from_device(char* c, int n)
61
{
61
{
62
	if (m_isEOF)
62
	if (m_isEOF || n < 0)
63
	{
63
	{
64
		return -1;
64
		return -1;
65
	}
65
	}
66
	int tmpInLen = 0;
66
	unsigned int un = n; 
67
	int offset = 0;
67
	unsigned int tmpInLen = 0;
68
	int lastRead = 0;
68
	unsigned int offset = 0;
69
	while (offset < n && m_istr.good())
69
	unsigned int lastRead = 0;
70
	while (offset < un && m_istr.good())
70
	{
71
	{
71
		if (m_inLen == -1)
72
		if (m_inLen == 0)
72
		{
73
		{
73
			m_istr >> std::hex >> m_inLen >> std::dec;
74
			m_istr >> std::hex >> m_inLen >> std::dec;
74
			if (m_istr.fail() || m_istr.bad())
75
			if (m_istr.fail() || m_istr.bad())
Lines 85-106 Link Here
85
			m_inPos = 0;
86
			m_inPos = 0;
86
			if (m_inLen == 0)
87
			if (m_inLen == 0)
87
			{
88
			{
88
				m_inLen = -1; // reset the state
89
				// reset the state
89
				m_isEOF = true;
90
				m_isEOF = true;
90
				m_pChunker->buildTrailerMap(); // build the trailer map
91
				m_pChunker->buildTrailerMap(); // build the trailer map
91
				return offset;
92
				return offset;
92
			}
93
			}
93
		}
94
		}
94
		// min of (n - offset) and (m_inLen - m_inPos)
95
		// min of (n - offset) and (m_inLen - m_inPos)
95
		tmpInLen = ((n - offset) < (m_inLen - m_inPos)) ? (n - offset)
96
		tmpInLen = ((un - offset) < (m_inLen - m_inPos)) ? (un - offset)
96
			: (m_inLen - m_inPos);
97
			: (m_inLen - m_inPos);
97
		m_istr.read(c + offset, tmpInLen);
98
		m_istr.read(c + offset, tmpInLen);
98
		lastRead = m_istr.gcount();
99
		lastRead = m_istr.gcount(); 
99
		offset += lastRead;
100
		offset += lastRead;
100
		m_inPos += lastRead;
101
		m_inPos += lastRead;
101
		if (m_inPos == m_inLen)
102
		if (m_inPos == m_inLen)
102
		{
103
		{
103
			m_inLen = -1;
104
			m_inLen = 0; 
104
			m_inPos = 0;
105
			m_inPos = 0;
105
			// don't need to skip trailing \r\n, because formatted input will
106
			// don't need to skip trailing \r\n, because formatted input will
106
			// skip it.
107
			// skip it.
Lines 117-123 Link Here
117
HTTPChunkedIStreamBuffer::resetInput()
118
HTTPChunkedIStreamBuffer::resetInput()
118
{
119
{
119
	initGetBuffer();
120
	initGetBuffer();
120
	m_inLen = -1;
121
	m_inLen = 0; 
121
	m_inPos = 0;
122
	m_inPos = 0;
122
	m_isEOF = false;
123
	m_isEOF = false;
123
}
124
}
(-)./src/http/common/OW_HTTPLenLimitIStream.hpp.orig (-7 / +7 lines)
Lines 47-68 Link Here
47
class OW_HTTP_API HTTPLengthLimitStreamBuffer : public BaseStreamBuffer
47
class OW_HTTP_API HTTPLengthLimitStreamBuffer : public BaseStreamBuffer
48
{
48
{
49
public:
49
public:
50
	HTTPLengthLimitStreamBuffer(std::istream& istr, Int64 length);
50
	HTTPLengthLimitStreamBuffer(std::istream& istr, UInt64 length);
51
	virtual ~HTTPLengthLimitStreamBuffer();
51
	virtual ~HTTPLengthLimitStreamBuffer();
52
	/**
52
	/**
53
	 * sets the Len to a new value,
53
	 * sets the Len to a new value,
54
	 * sets m_pos to zero, and m_isEnd to false
54
	 * sets m_pos to zero, and m_isEnd to false
55
	 */
55
	 */
56
	void resetLen(Int64 len);
56
	void resetLen(UInt64 len);
57
protected:
57
protected:
58
	virtual int buffer_from_device(char* c, int n);
58
	virtual int buffer_from_device(char* c, int n);
59
private:
59
private:
60
	std::istream& m_istr;
60
	std::istream& m_istr;
61
	
61
	
62
	// holds the content length.
62
	// holds the content length.
63
	Int64 m_length;
63
	UInt64 m_length;
64
	// keeps track of how much we've read.
64
	// keeps track of how much we've read.
65
	Int64 m_pos;
65
	UInt64 m_pos;
66
	// keeps track if we are at end of length.
66
	// keeps track if we are at end of length.
67
	bool m_isEnd;
67
	bool m_isEnd;
68
	// prohibit copying and assigning
68
	// prohibit copying and assigning
Lines 75-81 Link Here
75
class OW_HTTP_API HTTPLenLimitIStreamBase
75
class OW_HTTP_API HTTPLenLimitIStreamBase
76
{
76
{
77
public:
77
public:
78
	HTTPLenLimitIStreamBase(std::istream& istr, Int64 length)
78
	HTTPLenLimitIStreamBase(std::istream& istr, UInt64 length)
79
		: m_strbuf(istr, length) {}
79
		: m_strbuf(istr, length) {}
80
	HTTPLengthLimitStreamBuffer m_strbuf;
80
	HTTPLengthLimitStreamBuffer m_strbuf;
81
};
81
};
Lines 91-102 Link Here
91
	 * @param istr the original istream
91
	 * @param istr the original istream
92
	 * @param len the number of bytes to read before setting EOF.
92
	 * @param len the number of bytes to read before setting EOF.
93
	 */
93
	 */
94
	HTTPLenLimitIStream(std::istream& istr, Int64 len);
94
	HTTPLenLimitIStream(std::istream& istr, UInt64 len);
95
	/**
95
	/**
96
	 * Clear the EOF bit, and set the new length to len
96
	 * Clear the EOF bit, and set the new length to len
97
	 * @param len the new length to read before (re)setting EOF
97
	 * @param len the new length to read before (re)setting EOF
98
	 */
98
	 */
99
	void resetLen(Int64 len);
99
	void resetLen(UInt64 len);
100
private:
100
private:
101
	std::istream& m_istr;
101
	std::istream& m_istr;
102
	
102
	
(-)./src/http/common/OW_HTTPChunkedIStream.hpp.orig (-2 / +2 lines)
Lines 56-63 Link Here
56
		~HTTPChunkedIStreamBuffer();
56
		~HTTPChunkedIStreamBuffer();
57
	private:
57
	private:
58
		std::istream& m_istr;
58
		std::istream& m_istr;
59
		int m_inLen;
59
		unsigned int m_inLen;
60
		int m_inPos;
60
		unsigned int m_inPos;
61
		bool m_isEOF;
61
		bool m_isEOF;
62
		virtual int buffer_from_device(char* c, int n);
62
		virtual int buffer_from_device(char* c, int n);
63
		HTTPChunkedIStream* m_pChunker;
63
		HTTPChunkedIStream* m_pChunker;
(-)./src/http/common/OW_HTTPLenLimitIStream.cpp.orig (-6 / +7 lines)
Lines 41-47 Link Here
41
41
42
using std::istream;
42
using std::istream;
43
HTTPLengthLimitStreamBuffer::HTTPLengthLimitStreamBuffer(
43
HTTPLengthLimitStreamBuffer::HTTPLengthLimitStreamBuffer(
44
		istream& istr, Int64 length)
44
		istream& istr, UInt64 length)
45
	: BaseStreamBuffer(2048, "in"), m_istr(istr),
45
	: BaseStreamBuffer(2048, "in"), m_istr(istr),
46
	  m_length(length), m_pos(0), m_isEnd(false)
46
	  m_length(length), m_pos(0), m_isEnd(false)
47
// 2048 is a nice power of 2 that should be more than enough to hold most
47
// 2048 is a nice power of 2 that should be more than enough to hold most
Lines 56-67 Link Here
56
int
56
int
57
HTTPLengthLimitStreamBuffer::buffer_from_device(char* c, int n)
57
HTTPLengthLimitStreamBuffer::buffer_from_device(char* c, int n)
58
{
58
{
59
	if (m_isEnd)
59
	if (m_isEnd || n < 0)
60
	{
60
	{
61
		return -1;
61
		return -1;
62
	}
62
	}
63
	unsigned int un = n; 
63
	// min of n and (length - pos)
64
	// min of n and (length - pos)
64
	int tmpInLen = (n < (m_length - m_pos)) ? n : (m_length - m_pos);
65
	int tmpInLen = (un < (m_length - m_pos)) ? un : (m_length - m_pos);
65
	m_istr.read(c, tmpInLen);
66
	m_istr.read(c, tmpInLen);
66
	int lastRead = m_istr.gcount();
67
	int lastRead = m_istr.gcount();
67
	m_pos += lastRead;
68
	m_pos += lastRead;
Lines 73-79 Link Here
73
}
74
}
74
//////////////////////////////////////////////////////////////////////////////
75
//////////////////////////////////////////////////////////////////////////////
75
void
76
void
76
HTTPLengthLimitStreamBuffer::resetLen(Int64 len)
77
HTTPLengthLimitStreamBuffer::resetLen(UInt64 len)
77
{
78
{
78
	initGetBuffer();
79
	initGetBuffer();
79
	m_length = len;
80
	m_length = len;
Lines 82-94 Link Here
82
}
83
}
83
//////////////////////////////////////////////////////////////////////////////
84
//////////////////////////////////////////////////////////////////////////////
84
void
85
void
85
HTTPLenLimitIStream::resetLen(Int64 len)
86
HTTPLenLimitIStream::resetLen(UInt64 len)
86
{
87
{
87
	clear();
88
	clear();
88
	m_strbuf.resetLen(len);
89
	m_strbuf.resetLen(len);
89
}
90
}
90
//////////////////////////////////////////////////////////////////////////////
91
//////////////////////////////////////////////////////////////////////////////
91
HTTPLenLimitIStream::HTTPLenLimitIStream(istream& istr, Int64 len)
92
HTTPLenLimitIStream::HTTPLenLimitIStream(istream& istr, UInt64 len)
92
	: HTTPLenLimitIStreamBase(istr, len)
93
	: HTTPLenLimitIStreamBase(istr, len)
93
	, CIMProtocolIStreamIFC(&m_strbuf)
94
	, CIMProtocolIStreamIFC(&m_strbuf)
94
	, m_istr(istr)
95
	, m_istr(istr)
(-)./src/services/http/OW_HTTPSvrConnection.cpp.orig (-1 / +6 lines)
Lines 767-772 Link Here
767
			if (!cLen.empty())
767
			if (!cLen.empty())
768
			{
768
			{
769
				m_contentLength = cLen.toInt64();
769
				m_contentLength = cLen.toInt64();
770
				if (m_contentLength < 0)
771
				{
772
					m_errDetails = "Bad (negative) Content-Length"; 
773
					return SC_BAD_REQUEST;
774
				}
770
			}
775
			}
771
		}
776
		}
772
		// POST or M_POST, no chunking: test for content length
777
		// POST or M_POST, no chunking: test for content length
Lines 1228-1234 Link Here
1228
	}
1233
	}
1229
	else if (m_contentLength > 0)
1234
	else if (m_contentLength > 0)
1230
	{
1235
	{
1231
		rval = new HTTPLenLimitIStream(istr, m_contentLength);
1236
		rval = new HTTPLenLimitIStream(istr, UInt64(m_contentLength));
1232
	}
1237
	}
1233
	else
1238
	else
1234
	{
1239
	{
(-)./src/xml/OW_XMLUnescape.cpp.orig (-2 / +2 lines)
Lines 229-235 Link Here
229
#line 80
229
#line 80
230
	{
230
	{
231
		long lval = strtol( thisTokStart + 2, NULL, 10 );
231
		long lval = strtol( thisTokStart + 2, NULL, 10 );
232
		if (lval > CHAR_MAX)
232
		if (lval > CHAR_MAX || lval < 0)
233
		{
233
		{
234
			OW_THROWXML(XMLParseException::MALFORMED_REFERENCE, Format("XML escape code in unsupported range: %1", YYCURSOR - 1).c_str());
234
			OW_THROWXML(XMLParseException::MALFORMED_REFERENCE, Format("XML escape code in unsupported range: %1", YYCURSOR - 1).c_str());
235
		}
235
		}
Lines 258-264 Link Here
258
#line 69
258
#line 69
259
	{
259
	{
260
		long lval = strtol( thisTokStart + 3, NULL, 16 );
260
		long lval = strtol( thisTokStart + 3, NULL, 16 );
261
		if (lval > CHAR_MAX)
261
		if (lval > CHAR_MAX || lval < 0)
262
		{
262
		{
263
			OW_THROWXML(XMLParseException::MALFORMED_REFERENCE, Format("XML escape code in unsupported range: %1", YYCURSOR - 1).c_str());
263
			OW_THROWXML(XMLParseException::MALFORMED_REFERENCE, Format("XML escape code in unsupported range: %1", YYCURSOR - 1).c_str());
264
		}
264
		}

Return to bug 85842