PHPCMSV9无法上传附件,提示空信息的超级bug

这个问题折腾之久,浪费的时间、香烟之严重,就不多说了,反正Linux系统重做过两次,Nginx+Apache反复装了N次,都不成功。论坛也有很多解决办法,都治标不治本。

一开始发现系统在其它服务器上运行ok,就新部署的项目始终无法上传文件。所以一直把精力放到服务器的环境配置上了,比如上传大小限制,上传的目录权限,网站文件夹的权限设置,折腾了两个周末外加清明节。

悲催而操蛋的节日。

发现问题是无意中看到php的错误日志,定位到错误发生在移动临时上传文件到保存目录的地方,路径中多了一条下划线。

然后才看到这段离奇的代码

[php]
$temp_filename = $this->getname($fileext);
$savefile = $this->savepath.$temp_filename;
$savefile = preg_replace("/(php|phtml|php3|php4|jsp|exe|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(\.|$)/i", "_\\1\\2", $savefile);
$filepath = preg_replace(new_addslashes("|^".$this->upload_root."|"), "", $savefile);
if(!$this->overwrite && file_exists($savefile)) continue;
$upload_func = $this->upload_func;
if(@$upload_func($file[‘tmp_name’], $savefile)) {
$this->uploadeds++;
@chmod($savefile, 0644);
@unlink($file[‘tmp_name’]);
$file[‘name’] = iconv("utf-8",CHARSET,$file[‘name’]);
$uploadedfile = array(‘filename’=>$file[‘name’], ‘filepath’=>$filepath, ‘filesize’=>$file[‘size’], ‘fileext’=>$fileext, ‘fn’=>$file[‘fn’]);
$thumb_enable = is_array($thumb_setting) && ($thumb_setting[0] > 0 || $thumb_setting[1] > 0 ) ? 1 : 0;
$image = new image($thumb_enable,$this->siteid);
if($thumb_enable) {
$image->thumb($savefile,”,$thumb_setting[0],$thumb_setting[1]);
}
if($watermark_enable) {
$image->watermark($savefile, $savefile);
}
$aids[] = $this->add($uploadedfile);
}
[/php]

我理解这个程序员哥哥的意图是对非法的文件扩展名进行安全过滤,但发生一件很碉堡的事情,就是把整个路径给进行了过滤。

[php]$savefile = preg_replace("/(php|phtml|php3|php4|jsp|exe|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(\.|$)/i", "_\\1\\2", $savefile);[/php]

$savefile已经是一个完整的路径了,如/wwwroot/cn.php.net/uploadfile/2012/04/balabal.jpg,本身应该是对balabal.jpg进行过滤,现在把cn.php.net也算进去咯。
所以,如果某位朋友的域名中恰好出现了php|phtml|php3|php4|jsp|exe|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl+.,悲惨的生活就开始咯
解决办法很简单。注释掉这行或者改成下面的代码

[php]
   $temp_filename = $this->getname($fileext);
   $temp_filename = preg_replace("/(php|phtml|php3|php4|jsp|exe|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(\.|$)/i", "_\\1\\2", $temp_filename);
   $savefile = $this->savepath.$temp_filename;
[/php]

这个bug应该在V9所有版本中均存在,呜呼~~

我把修改之后的代码也发到这里了,献给所有欲哭无泪的战友们~~~

attachment.class

发表评论

回复 尘缘 取消回复

评论列表(3)

  • 懒懒的

    2012.10.4 18:10

    遇到同样问题,可是,把那行注视了,或者用你那个文件还是弄不好,求教

    回复
  • 尘缘

    2012.4.12 12:04

    跟踪这个问题,花了两个多小时,程序员的生命就是这样消失的!!!

    回复
  • sibtu

    2012.4.6 09:04

    感谢哥们儿,,,,我也是折腾了很多次都没解决,,,

    回复