Home  >  Article  >  Backend Development  >  Yaf中地图路由下delimiter的有关问题

Yaf中地图路由下delimiter的有关问题

WBOY
WBOYOriginal
2016-06-13 12:23:13795browse

Yaf中map路由下delimiter的问题

  由于map路由下用户请求的url会按照"/"分级对应到controllers下的目录下的Controller上,action则默认为indexAction,所以想要实现/key1/param1/key2/param2这种形式进行传参,就要通过delimiter来讲url分割成req_uri和query_str两个部分。

  在实践中,定义了delimiter(尽管并没有用到它的功能),这时,如果用户的请求(更多的是爬虫或扫站)无意中包含以下形式:/aaa/bbb[delimiter](xxx)?/key1/param1/key2/param2...,会造成程序崩溃。

  将这个问题提给鸟哥后,鸟哥迅速给出了修复(18~19行):

 

<span style="color: #008080;"> 1</span> <span style="color: #0000ff;">if</span> (Z_TYPE_P(delimer) == <span style="color: #008080;">IS_STRING</span><span style="color: #008080;"> 2</span>             &&<span style="color: #000000;"> Z_STRLEN_P(delimer)) {</span><span style="color: #008080;"> 3</span>         <span style="color: #0000ff;">if</span> ((query_str = <span style="color: #008080;">strstr</span>(req_uri, Z_STRVAL_P(delimer))) != <span style="color: #0000ff;">NULL</span><span style="color: #008080;"> 4</span>             && *(query_str - 1) == '/'<span style="color: #000000;">) {</span><span style="color: #008080;"> 5</span>             tmp  =<span style="color: #000000;"> req_uri;</span><span style="color: #008080;"> 6</span>             rest = query_str +<span style="color: #000000;"> Z_STRLEN_P(delimer);</span><span style="color: #008080;"> 7</span>             <span style="color: #0000ff;">if</span> (*rest == '\0'<span style="color: #000000;">) {</span><span style="color: #008080;"> 8</span>                 req_uri     = estrndup(req_uri, query_str -<span style="color: #000000;"> req_uri);</span><span style="color: #008080;"> 9</span>                 query_str     = <span style="color: #0000ff;">NULL</span><span style="color: #000000;">;</span><span style="color: #008080;">10</span> <span style="color: #000000;">                efree(tmp);</span><span style="color: #008080;">11</span>             } <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> (*rest == '/'<span style="color: #000000;">) {</span><span style="color: #008080;">12</span>                 req_uri     = estrndup(req_uri, query_str -<span style="color: #000000;"> req_uri);</span><span style="color: #008080;">13</span>                 query_str   =<span style="color: #000000;"> estrdup(rest);</span><span style="color: #008080;">14</span> <span style="color: #000000;">                efree(tmp);</span><span style="color: #008080;">15</span>             } <span style="color: #0000ff;">else</span><span style="color: #000000;"> {</span><span style="color: #008080;">16</span>                 query_str = <span style="color: #0000ff;">NULL</span><span style="color: #000000;">;</span><span style="color: #008080;">17</span> <span style="color: #000000;">            }</span><span style="color: #008080;">18</span>         } <span style="color: #0000ff;">else</span><span style="color: #000000;"> {</span><span style="color: #008080;">19</span>             query_str = <span style="color: #0000ff;">NULL</span><span style="color: #000000;">;</span><span style="color: #008080;">20</span>         }

通过delimer获取了query_str后,判断delimer的前一个字符是"/"的情况,却没有判断不是的情况,导致不符合/aaa/bbb/[delimer]/key1/param1/...形式的urk被截断成req_uri和query_str去解析,所以程序出现了问题。

  感谢鸟哥快速的答复!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn