php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53040 PHP crash/failure when called from bash-completion
Submitted: 2010-10-11 03:10 UTC Modified: 2011-03-01 08:30 UTC
From: myselfasunder at gmail dot com Assigned:
Status: Closed Package: CGI/CLI related
PHP Version: 5.3.3 OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: myselfasunder at gmail dot com
New email:
PHP Version: OS:

 

 [2010-10-11 03:10 UTC] myselfasunder at gmail dot com
Description:
------------
Calling PHP shell-scripts in any way (even if it doesn't do anything) from a bash-completion script causes the bash-completion script to fail (pressing TAB causes erratic spacing and tabbing at the console rather than producing options for completion). Bash and Perl calls work fine.

This refers to calling PHP in any of the following ways:
o php -r '..'
o php script.php
o ./script.php (this references '/usr/bin/php' with a shebang at the top)

I even tried calling Perl from the Bash, and then calling PHP from the Perl. No change in behavior. I tried with both 5.2 and the latest version of 5.3 .



Test script:
---------------
No test script necessary. Executing "php -r ''" in a bash completion script causes the failure.

Contents of ~/completiontest can be found at:

  http://www.randomingenuity.com/phpbugreference/20101010-2054_completiontest.php


You can commit this to the current bash-completion configuration by executing:

  ~$ . completiontest

To test without PHP, just comment-out the PHP call.

Expected result:
----------------
dustin@ubuntu:~$ . completiontest
dustin@ubuntu:~$ completiontest --<TAB><TAB>
--help     --verbose  --version
dustin@ubuntu:~$ completiontest --


Actual result:
--------------
dustin@ubuntu:~$ . completiontest
dustin@ubuntu:~$ completiontest --        |<-- Cursor moves to here.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-01 08:30 UTC] myselfasunder at gmail dot com
-Status: Open +Status: Closed
 [2011-03-01 08:30 UTC] myselfasunder at gmail dot com
Even the existence of a PHP call in a bash_completion.d script or any referenced Bash script may cause a complete completion failure, even when all STDERR and STDOUT output is suppressed (redirected to /dev/null), depending on what row it's effectively referenced from in the top-most bash_completion.d script. From what little material there is about this on the Internet, it appears that this problem might be a result of particular Ubuntu versions. No matter.

Bash completion with PHP works fine when used with the CGI variant. For example:

> /etc/bash_completion.d/foo
(Extends example at http://www.debian-administration.org/article/An_introduction_to_bash_completion_part_2)
============================
_foo()
{
    local cur opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"

    SAVE_IFS=$IFS
    IFS=","
    BUFFER="${COMP_WORDS[*]}"
    IFS=$SAVE_IFS

    opts=`echo "$COMP_CWORD:$BUFFER" | /tmp/completiontest.php`

    if [[ ${cur} == -* ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi
}

complete -F _foo foo

> /tmp/completiontest.php
=========================
#!/usr/bin/php5-cgi -q
<?php

// Just to 1) prevent writing to the bash_completion.d directory, and 
// 2) nail-down where our output file, below, will end up.
chdir(dirname(__FILE__));

// Grab completion information from STDIN. 
// Ex:
//   dustin@mx4:~$ foo --arg1 --arg2 --to_be_complet<TAB>^C
//   dustin@mx4:~$ cat /tmp/stdin.txt
//   3:foo,--arg1,--arg2,--to_be_complet
//
// Format of received STDIN information is "<number of tokens>:<comma-sep list of tokens>"
file_put_contents('stdin.txt', file_get_contents('php://stdin'));

// Output the space-separated completion possibilities.
print("--abc --def");
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Jul 22 10:01:25 2019 UTC