• R/O
  • HTTP
  • SSH
  • HTTPS

sslproxy: Commit

SSL Proxy


Commit MetaInfo

Revisão12db482f92cc52c6e4e3f6527caf8c2c08271cd0 (tree)
Hora2009-10-02 17:11:52
AutorKohei TANUMA <tanuma@user...>
CommiterTATEISHI Katsuyuki

Mensagem de Log

Check packet edit flag before memcpy.

Mudança Sumário

Diff

--- a/include/http_message.h
+++ b/include/http_message.h
@@ -67,7 +67,7 @@ protected:
6767 std::string _body;
6868 std::string incomplete;
6969 std::string raw_message;
70- bool modified;
70+ bool _modified;
7171 std::string convert_upper_camel_case(std::string) const;
7272
7373 public:
@@ -79,6 +79,7 @@ public:
7979 void header( std::string, std::string );
8080 std::string body() const;
8181 std::string body( std::string );
82+ bool modified() const;
8283
8384 std::string as_string();
8485 void parse( std::string );
--- a/src/http_message.cpp
+++ b/src/http_message.cpp
@@ -29,7 +29,7 @@
2929 */
3030 http_message::http_message()
3131 :
32- modified(false)
32+ _modified(false)
3333 {
3434 /*-------- DEBUG LOG --------*/
3535 if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) {
@@ -47,7 +47,7 @@ http_message::http_message()
4747 */
4848 http_message::http_message(std::string header)
4949 :
50- modified(false)
50+ _modified(false)
5151 {
5252 /*-------- DEBUG LOG --------*/
5353 if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) {
@@ -128,18 +128,18 @@ void http_message::header(std::string field_name, std::string field_value)
128128 if (field_value != "") {
129129 if ( _header.get<field_map>().replace(it, field(name, field_value)) ) {
130130 changed = true;
131- this->modified = true;
131+ this->_modified = true;
132132 }
133133 }
134134 else {
135135 _header.get<field_map>().erase(it);
136136 changed = true;
137- this->modified = true;
137+ this->_modified = true;
138138 }
139139 }
140140 if (!changed && field_value != "") {
141141 _header.get<field_map>().insert( field(name, field_value) );
142- this->modified = true;
142+ this->_modified = true;
143143 }
144144 }
145145 catch (...) {
@@ -194,7 +194,7 @@ std::string http_message::body(std::string _body)
194194
195195 std::string ret = this->_body;
196196 this->_body = _body;
197- this->modified = true;
197+ this->_modified = true;
198198
199199 /*-------- DEBUG LOG --------*/
200200 if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) {
@@ -208,6 +208,26 @@ std::string http_message::body(std::string _body)
208208 }
209209
210210 /*!
211+ * Get modified flag function.
212+ *
213+ * @return modified flag
214+ */
215+bool http_message::modified() const
216+{
217+ /*-------- DEBUG LOG --------*/
218+ if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) {
219+ LOGGER_PUT_LOG_DEBUG(LOG_CAT_PACKET_EDIT_HTTP, 66,
220+ "in_function : bool http_message::modified(void)");
221+ LOGGER_PUT_LOG_DEBUG(LOG_CAT_PACKET_EDIT_HTTP, 67,
222+ "out_function : bool http_message::modified(void) : "
223+ "return(%s)", this->_modified ? "true" : "false");
224+ }
225+ /*------ DEBUG LOG END ------*/
226+
227+ return this->_modified;
228+}
229+
230+/*!
211231 * Get full HTTP message function.
212232 *
213233 * @return HTTP message
@@ -221,7 +241,7 @@ std::string http_message::as_string()
221241 }
222242 /*------ DEBUG LOG END ------*/
223243
224- if (this->modified)
244+ if (this->_modified)
225245 this->rebuild();
226246
227247 /*-------- DEBUG LOG --------*/
--- a/src/http_request.cpp
+++ b/src/http_request.cpp
@@ -107,7 +107,7 @@ std::string http_request::method(std::string _method)
107107
108108 std::string ret = this->_method;
109109 this->_method = _method;
110- this->modified = true;
110+ this->_modified = true;
111111
112112 /*-------- DEBUG LOG --------*/
113113 if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) {
@@ -159,7 +159,7 @@ std::string http_request::request_uri(std::string _request_uri)
159159
160160 std::string ret = this->_request_uri;
161161 this->_request_uri = _request_uri;
162- this->modified = true;
162+ this->_modified = true;
163163
164164 /*-------- DEBUG LOG --------*/
165165 if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) {
@@ -211,7 +211,7 @@ std::string http_request::http_version(std::string _http_version)
211211
212212 std::string ret = this->_http_version;
213213 this->_http_version = _http_version;
214- this->modified = true;
214+ this->_modified = true;
215215
216216 /*-------- DEBUG LOG --------*/
217217 if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) {
@@ -265,7 +265,7 @@ std::string http_request::as_string()
265265 }
266266 /*------ DEBUG LOG END ------*/
267267
268- if (this->modified)
268+ if (this->_modified)
269269 this->rebuild();
270270
271271 /*-------- DEBUG LOG --------*/
--- a/src/http_response.cpp
+++ b/src/http_response.cpp
@@ -107,7 +107,7 @@ std::string http_response::http_version(std::string _http_version)
107107
108108 std::string ret = this->_http_version;
109109 this->_http_version = _http_version;
110- this->modified = true;
110+ this->_modified = true;
111111
112112 /*-------- DEBUG LOG --------*/
113113 if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) {
@@ -159,7 +159,7 @@ std::string http_response::status_code(std::string _status_code)
159159
160160 std::string ret = this->_status_code;
161161 this->_status_code = _status_code;
162- this->modified = true;
162+ this->_modified = true;
163163
164164 /*-------- DEBUG LOG --------*/
165165 if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) {
@@ -211,7 +211,7 @@ std::string http_response::reason_phrase(std::string _reason_phrase)
211211
212212 std::string ret = this->_reason_phrase;
213213 this->_reason_phrase = _reason_phrase;
214- this->modified = true;
214+ this->_modified = true;
215215
216216 /*-------- DEBUG LOG --------*/
217217 if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_PACKET_EDIT_HTTP)) {
@@ -265,7 +265,7 @@ std::string http_response::as_string()
265265 }
266266 /*------ DEBUG LOG END ------*/
267267
268- if (this->modified)
268+ if (this->_modified)
269269 this->rebuild();
270270
271271 /*-------- DEBUG LOG --------*/
--- a/src/packet_editor.cpp
+++ b/src/packet_editor.cpp
@@ -138,16 +138,18 @@ void packet_editor::edit_client(char* client_msg, size_t& client_length)
138138 * Insert other protocol editor.
139139 */
140140
141- std::string edited = request.as_string();
142- // New client message is too long (over buffer size)
143- if (edited.size() > MAX_BUFFER_SIZE) {
144- LOGGER_PUT_LOG_ERROR(LOG_CAT_PACKET_EDIT, 1, "Edited message is too long. Drop message.");
145- }
146- else {
147- // Set new client message size.
148- client_length = edited.size();
149- // Set new client message.
150- memcpy(client_msg, edited.c_str(), client_length);
141+ if (request.modified()) {
142+ std::string edited = request.as_string();
143+ // New client message is too long (over buffer size)
144+ if (edited.size() > MAX_BUFFER_SIZE) {
145+ LOGGER_PUT_LOG_ERROR(LOG_CAT_PACKET_EDIT, 1, "Edited message is too long. Drop message.");
146+ }
147+ else {
148+ // Set new client message size.
149+ client_length = edited.size();
150+ // Set new client message.
151+ memcpy(client_msg, edited.c_str(), client_length);
152+ }
151153 }
152154
153155 /*-------- DEBUG LOG --------*/
@@ -234,16 +236,18 @@ void packet_editor::edit_server(char* server_msg, size_t& server_length)
234236 * Insert other protocol editor.
235237 */
236238
237- std::string edited = response.as_string();
238- // New server message is too long (over buffer size)
239- if (edited.size() > MAX_BUFFER_SIZE) {
240- LOGGER_PUT_LOG_ERROR(LOG_CAT_PACKET_EDIT, 2, "Edited message is too long. Drop message.");
241- }
242- else {
243- // Set new server message size.
244- server_length = edited.size();
245- // Set new server message.
246- memcpy(server_msg, edited.c_str(), server_length);
239+ if (response.modified()) {
240+ std::string edited = response.as_string();
241+ // New server message is too long (over buffer size)
242+ if (edited.size() > MAX_BUFFER_SIZE) {
243+ LOGGER_PUT_LOG_ERROR(LOG_CAT_PACKET_EDIT, 2, "Edited message is too long. Drop message.");
244+ }
245+ else {
246+ // Set new server message size.
247+ server_length = edited.size();
248+ // Set new server message.
249+ memcpy(server_msg, edited.c_str(), server_length);
250+ }
247251 }
248252
249253 /*-------- DEBUG LOG --------*/
Show on old repository browser