struts-1.2.9.jar修改包路径、源码编译记录

修改目的:struts-1.2.9 有CVE-2014-0114漏洞:http://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=commons,
各方面原因替换mvc框架不现实,因此计划维护自己的struts分支修复该漏洞
本次只记录struts-1.2.9源码修改包名包路径过程
升级步骤
1、准备2个包:通过maven获取struts源码包(struts-1.2.9-sources.jar)和编译后的jar包(struts-1.2.9.jar)
2、修改struts源码org/apache/struts目录为com/hhfclub/struts目录并放置到原项目根目录下
3、从struts-1.2.9.jar的META-INF中取出tlds标签库模板放置到原项目的WEB-INF下(源码包中没有这些tld标签库)
tld标签库目录
4、从struts-1.2.9.jar的org/apache/struts/中复制resources目录到com/hhfclub/struts/下(源码中没有该目录,目录下存放的是dtd约束文件)
dtd约束文件目录
5、删除原项目pom文件中对struts的依赖
6、全局搜索org/apache/struts替换为com/hhfclub/struts , 包括xml,tld,java,jsp文件
7、解决部分项目编译错误
8、启动试试

遇到的问题:
1、jar包里有struts路径引用的需先获取jar包源码,然后尝试修改覆盖
2、升级commons-logging 从1.1.1到1.2
3、升级commons-beanutils 1.8.3到1.9.3后,项目启动时struts使用commons-Digester解析xml配置文件时会有无限等待的情况(如下图),暂未解决,commons-beanutils版本回退到1.8.3后问题消失
在这里插入图片描述
com.hhfclub.struts.action.ActionServlet.parseModuleConfigFile(ActionServlet.java:739)相关源码:

/**
     * <p>Parses one module config file.</p>
     *
     * @param digester Digester instance that does the parsing
     * @param path The path to the config file to parse.
     *
     * @throws UnavailableException if file cannot be read or parsed
     * @since Struts 1.2
     */
    protected void parseModuleConfigFile(Digester digester, String path)
        throws UnavailableException {

        InputStream input = null;
        try {
            URL url = getServletContext().getResource(path);

            // If the config isn't in the servlet context, try the class loader
            // which allows the config files to be stored in a jar
            if (url == null) {
                url = getClass().getResource(path);
            }
            
            if (url == null) {
                String msg = internal.getMessage("configMissing", path);
                log.error(msg);
                throw new UnavailableException(msg);
            }
	    
            InputSource is = new InputSource(url.toExternalForm());
            input = url.openStream();
            is.setByteStream(input);
            log.info("Parsing struts config file:"+path);
            digester.parse(is);
        } catch (MalformedURLException e) {
            handleConfigException(path, e);
        } catch (IOException e) {
            handleConfigException(path, e);
        } catch (SAXException e) {
            handleConfigException(path, e);
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    throw new UnavailableException(e.getMessage());
                }
            }
        }
    }

如需重新打个新的struts包只需把以上的struts源码和其依赖的jar包放到一个单独的maven项目环境下通过maven打包即可
struts依赖包可以从struts-1.2.9.jar包里的META-INF/MANIFEST.MF文件查看,但需要注意依赖包的版本问题,可以参考
https://mvnrepository.com/artifact/struts/struts/1.2.9
以下贴出我项目依赖的版本号

依赖包版本号
commons-beanutils.jar1.8.3
commons-digester.jar1.8
commons-fileupload.jar1.4
commons-logging.jar1.2
commons-validator.jar1.4
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值