2012-01-14 63 views
17

我有以下工作代码:警告:的preg_match():内部pcre_fullinfo()

$test = '123456'; 

$int = preg_match('/^\d+$/', $test, $matches); 

print_r(array($int, $matches)); 

然而,当我execute it on codepad我得到的错误:

Warning: preg_match(): Internal pcre_fullinfo() error -3 on line 5

但代码上运行我的自己的机器(和代码应该罚款恕我直言)。

我需要在将来分发我的代码,所以如果根据某些配置它会中断会很糟糕。那么,键盘在它上面破坏的原因是什么?通过键盘执行

回答

29

代码在一个非常有限的环境中运行:

Code execution is handled by a supervisor based on geordi. The strategy is to run everything under ptrace, with many system calls disallowed or ignored. Compilers and final executables are both executed in a chroot jail, with strict resource limits. The supervisor is written in Haskell.

虽然这是你所期望打破正则表达式引擎它很可能是PCRE库内部使用的东西,被阻塞的没有键盘环境。没有生产系统使用这种严格的限制,所以你应该安全地在你的应用程序中使用该代码。

错误代码代表“PCRE_ERROR_BADOPTION - 值什么是无效的”。 但是,发生错误的PHP源代码是rc = pcre_fullinfo(pce->re, extra, PCRE_INFO_CAPTURECOUNT, &num_subpats);,它使用了一个常数什么。所以这显然意味着pcre库在键盘上被破坏。

如果您想要完全安全,您可以使用libpcre编写一个小型C程序,在同一个正则表达式中调用该函数。