Bug 3248 - SFTP can not sort files by modification time
Summary: SFTP can not sort files by modification time
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sftp (show other bugs)
Version: 8.4p1
Hardware: Other Linux
: P5 enhancement
Assignee: Damien Miller
URL:
Keywords:
Depends on:
Blocks: V_8_5
  Show dependency treegraph
 
Reported: 2021-01-04 22:51 AEDT by Jakub Jelen
Modified: 2021-04-23 15:10 AEST (History)
1 user (show)

See Also:


Attachments
proposed patch from Red Hat Bug (649 bytes, text/plain)
2021-01-04 22:51 AEDT, Jakub Jelen
no flags Details
tweaked patch (710 bytes, patch)
2021-01-08 13:39 AEDT, Damien Miller
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelen 2021-01-04 22:51:22 AEDT
Created attachment 3463 [details]
proposed patch from Red Hat Bug

Originally reported as Red Hat Bug with patch:

https://bugzilla.redhat.com/show_bug.cgi?id=1909988

When sorting files based on the modification time from remote glob in the client SFTP, the return values from sglob_comp() is wrong (1 or 0 and 0 or -1 with -r flag) causing the files are incorrectly sorted inside of the qsort, which expects -1, 0 or 1. For more information, see the analysis in the above bug.
Comment 1 Damien Miller 2021-01-08 13:39:19 AEDT
Created attachment 3464 [details]
tweaked patch

I think it also needs to handle the == case.
Comment 2 Damien Miller 2021-01-08 13:45:20 AEDT
fix committed and will be in OpenSSH 8.5
Comment 3 Jakub Jelen 2021-01-08 22:13:32 AEDT
(In reply to Damien Miller from comment #1)
> Created attachment 3464 [details]
> tweaked patch
> 
> I think it also needs to handle the == case.

Thank you. Indeed, the equal is a corner case but your patch looks fine.
Comment 4 Damien Miller 2021-04-23 15:10:22 AEST
closing resolved bugs as of 8.6p1 release