2012-01-14 62 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程序,在同一個正則表達式中調用該函數。