The delimiter problem in the map route in Yaf, yafdelimiter
Because the url requested by the user under the map route will correspond to the Controller under the controllers directory according to the "/" classification, the default action is indexAction, therefore, to implement parameter passing in the form of/key1/param1/key2/param2, we need to use delimiter to split the url into two parts: req_uri and query_str.
In practice, delimiter is defined (although it does not use its functions). In this case, if a user's request (more crawler or scan site) inadvertently contains the following forms: /aaa/bbb [delimiter] (xxx )? /Key1/param1/key2/param2. .., causing program crash.
After I raised this question to laruence, laruence quickly provided a solution (18 ~ 19 rows ):
1 if (Z_TYPE_P(delimer) == IS_STRING 2 && Z_STRLEN_P(delimer)) { 3 if ((query_str = strstr(req_uri, Z_STRVAL_P(delimer))) != NULL 4 && *(query_str - 1) == '/') { 5 tmp = req_uri; 6 rest = query_str + Z_STRLEN_P(delimer); 7 if (*rest == '\0') { 8 req_uri = estrndup(req_uri, query_str - req_uri); 9 query_str = NULL;10 efree(tmp);11 } else if (*rest == '/') {12 req_uri = estrndup(req_uri, query_str - req_uri);13 query_str = estrdup(rest);14 efree(tmp);15 } else {16 query_str = NULL;17 }18 } else {19 query_str = NULL;20 }
After query_str is obtained through delimiters, the system determines whether the first character of delimiters is "/", but does not judge whether it is not, cause/aaa/bbb/[deletable]/key1/param1 /... the format of urk is truncated into req_uri and query_str for parsing, so the program has a problem.
Thank you for your quick response!