Bash php silence segfault

I need to prevent all the php output, https://stackoverflow.com/a/166268/2129/11/11/11/11/11/11/11/en.html .

php to create segfault in pcre extension: https://ilia.ws/archives/5_Top_10_ways_to_crash_PHP.html

<?php # prce-bug.php preg_match('/(.(?!b))*/', str_repeat("a", 10000)); 

In my testing, this still outputs:

 user@host ~/crash-php $ php pcre-bug.php Segmentation fault (core dumped) user@host ~/crash-php $ php pcre-bug.php >/dev/null 2>&1 Segmentation fault (core dumped) 

Thus, even with shell output redirection, the output is output to my terminal.

+2
bash php io-redirection
Sep 01 '15 at 21:42
source share
3 answers

I found that using a new instance of the sh shell will capture system death messages for the process, such as Segmentation Defect and Killed.

 sh -c 'php pcre-bug.php' >/dev/null 2>&1 

However, the input arguments do not apply to php, but rather to the sh instance, which does nothing with them.

+1
Sep 01 '15 at 10:45
source share

Output redirection applies to the process, however, the segfault message is generated by bash itself as a result of the child process dying using segfault.

One solution would be to do something like this:

 echo `php pcre-bug.php >/dev/null 2>&1` 
+1
Sep 01 '15 at
source share

You can use the compound commands { } :

 $ { php pcre-bug.php; } &>/dev/null $ $ echo $? 139 

From Bash Manually β†’ 3.2.4 Compound Commands β†’ 3.2.4.3 Grouping and man bash commands :

Compound teams

{list; }

the list is simply executed in the current shell environment. the list must end with a newline or semicolon.

This is called a team team. Return status is the exit status of the list. Please note: unlike metacharacters (and), {and} are reserved words and must occur where the reserved word is allowed.

Since they do not cause word breaks, they must be separated from the list by a space or other shell metacharacter.

However, using ( ) does not work, and I do not know why:

 $ ( php pcre-bug.php ) &>/dev/null Segmentation fault (core dumped) 
+1
Sep 02 '15 at 10:34
source share



All Articles