This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author cdgriffith
Recipients cdgriffith
Date 2021-03-06.18:52:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1615056762.46.0.090803448155.issue43423@roundup.psfhosted.org>
In-reply-to
Content
It is possible to run into an IndexError in the subprocess module's _communicate function.

```
    return run(
  File "subprocess.py", line 491, in run
  File "subprocess.py", line 1024, in communicate
  File "subprocess.py", line 1418, in _communicate
IndexError: list index out of range
```

The lines in question are: 

```
            if stdout is not None:
                stdout = stdout[0]
            if stderr is not None:
                stderr = stderr[0]
```

I believe this is due to the fact there is no safety checking to make sure that self._stdout_buff and self._stderr_buff have any content in them after being set to empty lists. 

The fix I suggest is to change the checks from `if stdout is not None` to simply `if stdout` to make sure it is a populated list. 

Example fixed code: 

```
            if stdout:
                stdout = stdout[0]
            if stderr:
                stderr = stderr[0]
```

If a more stringent check is required, we could expand that out to check type and length, such as `isinstance(stdout, list) and len(stdout) > 0:` but that is more then necessary currently.
History
Date User Action Args
2021-03-06 18:52:42cdgriffithsetrecipients: + cdgriffith
2021-03-06 18:52:42cdgriffithsetmessageid: <1615056762.46.0.090803448155.issue43423@roundup.psfhosted.org>
2021-03-06 18:52:42cdgriffithlinkissue43423 messages
2021-03-06 18:52:42cdgriffithcreate