[Twisted-Python] Negative error code breaks twisted.conch

Peter Westlake peter.westlake at pobox.com
Mon Jan 14 08:23:28 MST 2019


An SSCCE:

from twisted.internet import error
from twisted.python import failure
from twisted.conch.ssh.session import SSHSessionProcessProtocol
from mock import MagicMock

err = error.ProcessTerminated(-1)
fail = failure.Failure(err)
session = MagicMock()
proto = SSHSessionProcessProtocol(session)
proto.processEnded(fail)


That fails with:

Traceback (most recent call last):
  File ".../negexit.py", line 10, in <module>
    proto.processEnded(fail)
  File "/usr/lib64/python2.7/site-
  packages/twisted/conch/ssh/session.py", line 279, in processEnded    struct.pack('>L', err.exitCode))
struct.error: integer out of range for 'L' format code

I'm running an SSH server on Windows, where negative exit codes
can happen.
Passing negative numbers to a ">L" format was allowed in Python before
2.6, where the number was treated as an unsigned int of the same bit
pattern. It was deprecated in 2.6, and became an error in 2.7. It's only
just become a problem for me because I'm updating a 10 year old SSH
server that has been running under 2.4 all this time.
Presumably the fix is to bit-mask the exitCode? I was able to work
around the error by doing that in a copy of _dumbwin32proc.py which was
copied into the project (historical reasons, don't ask) but it would be
nice to have a proper upstream fix. Not least because I want to purge
the copied-in file, as you can imagine.
Peter.





-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20190114/85622298/attachment.html>


More information about the Twisted-Python mailing list