• R/O
  • SSH
  • HTTPS

bchan: Commit


Commit MetaInfo

Revision668 (tree)
Time2015-03-19 01:40:22
Authorornse01

Log Message

fix infinit loop which cause by empty field's value.

Change Summary

Incremental Difference

--- bchanf/trunk/src/coding/test_htmlform_urlencoder.c (revision 667)
+++ bchanf/trunk/src/coding/test_htmlform_urlencoder.c (revision 668)
@@ -64,6 +64,9 @@
6464 if (cont == False) {
6565 break;
6666 }
67+ if (len == 0) {
68+ continue;
69+ }
6770 result = realloc(result, result_len + len + 1);
6871 if (result == NULL) {
6972 ret = UNITTEST_RESULT_FAIL;
@@ -149,6 +152,21 @@
149152 return test_htmlform_urlencoder_common(&testdata);
150153 }
151154
155+LOCAL UNITTEST_RESULT test_htmlform_urlencoder_5()
156+{
157+ htmlform_field src[] = {
158+ (htmlform_field){"aaa", 3, "", 0},
159+ (htmlform_field){"cc", 2, "", 0},
160+ };
161+ W src_len = 2;
162+ UB expected[] = "aaa=&cc=";
163+ W expected_len = strlen(expected);
164+ urlencoder_testdata_t testdata = {
165+ src, src_len, expected, expected_len
166+ };
167+ return test_htmlform_urlencoder_common(&testdata);
168+}
169+
152170 EXPORT VOID test_htmlform_urlencoder_main(unittest_driver_t *driver)
153171 {
154172 UNITTEST_DRIVER_REGIST(driver, test_htmlform_urlencoder_1);
@@ -155,4 +173,5 @@
155173 UNITTEST_DRIVER_REGIST(driver, test_htmlform_urlencoder_2);
156174 UNITTEST_DRIVER_REGIST(driver, test_htmlform_urlencoder_3);
157175 UNITTEST_DRIVER_REGIST(driver, test_htmlform_urlencoder_4);
176+ UNITTEST_DRIVER_REGIST(driver, test_htmlform_urlencoder_5);
158177 }
--- bchanf/trunk/src/coding/htmlform_urlencoder.c (revision 667)
+++ bchanf/trunk/src/coding/htmlform_urlencoder.c (revision 668)
@@ -89,11 +89,14 @@
8989 switch (encoder->state) {
9090 case HTMLFORM_URLENCODER_STATE_NAME:
9191 DP_STATE("NAME");
92- htmlform_urlencoder_convert(encoder, field->name[encoder->src_pos], str, len);
93- encoder->src_pos++;
9492 if (encoder->src_pos == field->name_len) {
9593 encoder->state = HTMLFORM_URLENCODER_STATE_EQUAL;
94+ *str = encoder->buf;
95+ *len = 0;
96+ return True;
9697 }
98+ htmlform_urlencoder_convert(encoder, field->name[encoder->src_pos], str, len);
99+ encoder->src_pos++;
97100 return True;
98101 case HTMLFORM_URLENCODER_STATE_EQUAL:
99102 DP_STATE("EQUAL");
@@ -104,12 +107,15 @@
104107 return True;
105108 case HTMLFORM_URLENCODER_STATE_VALUE:
106109 DP_STATE("VALUE");
107- htmlform_urlencoder_convert(encoder, field->value[encoder->src_pos], str, len);
108- encoder->src_pos++;
109110 if (encoder->src_pos == field->value_len) {
110111 encoder->state = HTMLFORM_URLENCODER_STATE_AMP;
111112 encoder->field_index++;
113+ *str = encoder->buf;
114+ *len = 0;
115+ return True;
112116 }
117+ htmlform_urlencoder_convert(encoder, field->value[encoder->src_pos], str, len);
118+ encoder->src_pos++;
113119 return True;
114120 case HTMLFORM_URLENCODER_STATE_AMP:
115121 DP_STATE("AMP");
Show on old repository browser