Paramiko raises an exception if self._cwd is a unicode object

Bug #411099 reported by firewing1
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
paramiko
Fix Committed
Medium
Robey Pointer

Bug Description

If a user calls chdir(path) on a SFTP client object (where path contains special characters) and then attempts to transfer files relative to the current directory, Paramiko will be unable to upload files when given a relative destination. The exception Paramiko outputs is:
Exception: unknown type for u'/Users/myuser/ba\u0300ckuptest/testfiles/file0/' type <type 'unicode'>

I looked at the code in sftp_client.py and it seems the function _adjust_cwd is the problem. It does ensure that the "path" argument is not a unicode object and encodes "path" if it is, however it does not perform this same check on self._cwd. When calling chdir(path), normalize(path) is used to set self._cwd. Since normalize returns a Unicode object, if "path" is not an absolute path and the current directory contains special characters, then Paramiko fails with the exception above.

I've attached a patch which changes the behavior of _adjust_cwd so that instead of returning the new paths immediately, the new paths are assigned to a temporary final_path variable. The unicode check is performed last to ensure that final_path is not a Unicode object.

Revision history for this message
firewing1 (s-adam) wrote :
Robey Pointer (robey)
Changed in paramiko:
status: New → Confirmed
importance: Undecided → Medium
assignee: nobody → Robey Pointer (robey)
milestone: none → 1.7.6
Revision history for this message
Robey Pointer (robey) wrote :

it sounds like the real problem is normalize returning a unicode object, so if i make chdir turn the path into utf-8, that should also fix it.

Robey Pointer (robey)
Changed in paramiko:
status: Confirmed → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.