Bug 3248

Summary: SFTP can not sort files by modification time
Product: Portable OpenSSH Reporter: Jakub Jelen <jjelen>
Component: sftpAssignee: Damien Miller <djm>
Status: CLOSED FIXED    
Severity: enhancement CC: djm
Priority: P5    
Version: 8.4p1   
Hardware: Other   
OS: Linux   
Bug Depends on:    
Bug Blocks: 3217    
Attachments:
Description Flags
proposed patch from Red Hat Bug
none
tweaked patch none

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