@@ -78,36 +78,50 @@ static void test_isatom(void)
78
78
static void test_istag(void)
79
79
{
80
80
const char hello[] = "hello";
81
+ const char *const forbidden_http_methods[] = {
82
+ "ACL", "BIND", "LOCK", "MKCALENDAR", "MKCOL", "PATCH", "POST",
83
+ "PROPFIND", "PROPPATCH", "PUT", "REPORT", "SEARCH", "UNBIND",
84
+ };
85
+ const int n_forbidden_http_methods = sizeof(forbidden_http_methods)
86
+ / sizeof(forbidden_http_methods[0]);
81
87
char tmp[2] = { 0 };
82
88
int i;
83
89
84
90
/* if it's not an atom, it definitely can't be a tag */
85
91
for (i = 0; i <= 0xff; i++) {
86
92
tmp[0] = (char) i;
87
93
if (!imparse_isatom(tmp))
88
- CU_ASSERT_EQUAL(imparse_istag(tmp), 0);
94
+ CU_ASSERT_EQUAL(imparse_istag(tmp, 0 ), 0);
89
95
}
90
96
91
97
/* there used to be an explicit (albeit redundant) check for this case */
92
98
tmp[0] = '*';
93
- CU_ASSERT_EQUAL(imparse_istag(tmp), 0);
99
+ CU_ASSERT_EQUAL(imparse_istag(tmp, 0 ), 0);
94
100
95
101
/* "." tag idiomatic when telnetting to imap server, don't break that */
96
102
tmp[0] = '.';
97
- CU_ASSERT_NOT_EQUAL(imparse_istag(tmp), 0);
103
+ CU_ASSERT_NOT_EQUAL(imparse_istag(tmp, 0 ), 0);
98
104
99
105
/* angle brackets exploitable in cross-protocol reflection attacks */
100
106
tmp[0] = '<';
101
- CU_ASSERT_EQUAL(imparse_istag(tmp), 0);
107
+ CU_ASSERT_EQUAL(imparse_istag(tmp, 0 ), 0);
102
108
tmp[0] = '>';
103
- CU_ASSERT_EQUAL(imparse_istag(tmp), 0);
109
+ CU_ASSERT_EQUAL(imparse_istag(tmp, 0 ), 0);
104
110
105
111
/* colon character in tag suggests confused HTTP client */
106
112
tmp[0] = ':';
107
- CU_ASSERT_EQUAL(imparse_istag(tmp), 0);
113
+ CU_ASSERT_EQUAL(imparse_istag(tmp, 0 ), 0);
108
114
109
115
/* make sure it doesn't just always return zero... */
110
- CU_ASSERT_NOT_EQUAL(imparse_istag(hello), 0);
116
+ CU_ASSERT_NOT_EQUAL(imparse_istag(hello, 0), 0);
117
+
118
+ for (i = 0; i < n_forbidden_http_methods; i++) {
119
+ /* reject forbidden HTTP method used as tag on the first command */
120
+ CU_ASSERT_EQUAL(imparse_istag(forbidden_http_methods[i], 0), 0);
121
+
122
+ /* but permit during an established session */
123
+ CU_ASSERT_NOT_EQUAL(imparse_istag(forbidden_http_methods[i], 1), 0);
124
+ }
111
125
}
112
126
113
127
static void test_parse_range(void)
0 commit comments