Note: This bug is displayed in read-only format because
the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
DescriptionMasahiro Matsuya
2020-12-22 09:13:50 UTC
Created attachment 1741313[details]
proposed patch
Description of problem:
The ls -t option doesn't sort the globbed files upon the modification time.
sftp> ls -ltr SG*
-rw-r--r-- ? 0 0 0 Dec 22 17:43 SG0003
-rw-r--r-- ? 0 0 0 Dec 22 17:40 SG0001
-rw-r--r-- ? 0 0 0 Dec 22 17:45 SG0002
The root cause is in usage of the timespeccmp macro in sglob_comp().
The timespeccmp macro returns 0 (false) or 1 (true) as the result of comparison with "<". When the -r option is not used, sglob_comp() returns
1 or 0 only. When the -r option is used, it returns -1 or 0 only
sglob_comp(const void *aa, const void *bb)
{
...
int rmul = sort_flag & LS_REVERSE_SORT ? -1 : 1;
...
else if (sort_flag & LS_TIME_SORT) {
#if defined(HAVE_STRUCT_STAT_ST_MTIM)
return (rmul * timespeccmp(&as->st_mtim, &bs->st_mtim, <));
The following is about the comparison function of qsort() in man qsort.
In man qsort
The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be
respectively less than, equal to, or greater than the second. If two members compare as equal, their order in the sorted array is
undefined.
So, the above sglob_comp() doesn't meet this requirement.
It should return -1, 0, or 1.
Version-Release number of selected component (if applicable):
openssh-8.0p1-5.el8.x86_64
How reproducible:
Always
Steps to Reproduce:
1. Create three files in /root on any ssh server
# cd /root
# touch SG0001
wait more than one minute
# touch SG0003
wait more than one minute
# touch SG0002
NOTE: We can see the difference of the modification time in the "ls -lt" output by waiting more than one minute.
2. connect with sftp from *RHEL8.3 client*
# sftp root@<hostname>
NOTE: sorting is done in the sftp client side.
3. Run "ls -ltr SG*"
Actual results:
Sorting with -l option doesn't work.
sftp> ls -ltr SG*
-rw-r--r-- ? 0 0 0 Dec 22 17:43 SG0003
-rw-r--r-- ? 0 0 0 Dec 22 17:40 SG0001
-rw-r--r-- ? 0 0 0 Dec 22 17:45 SG0002
Expected results:
Sorting with -l option works.
sftp> ls -ltr SG*
-rw-r--r-- ? 0 0 0 Dec 22 17:40 SG0001
-rw-r--r-- ? 0 0 0 Dec 22 17:43 SG0003
-rw-r--r-- ? 0 0 0 Dec 22 17:45 SG0002
Thank you for the report. It is an issue in the upstream openssh too so I filled and attached an upstream bug.
It looks simple enough so we should be able to backport this for next release.
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.
For information on the advisory (Moderate: openssh security update), and where to find the updated
files, follow the link below.
If the solution does not work for you, open a new bug report.
https://access.redhat.com/errata/RHSA-2021:4368
Created attachment 1741313 [details] proposed patch Description of problem: The ls -t option doesn't sort the globbed files upon the modification time. sftp> ls -ltr SG* -rw-r--r-- ? 0 0 0 Dec 22 17:43 SG0003 -rw-r--r-- ? 0 0 0 Dec 22 17:40 SG0001 -rw-r--r-- ? 0 0 0 Dec 22 17:45 SG0002 The root cause is in usage of the timespeccmp macro in sglob_comp(). The timespeccmp macro returns 0 (false) or 1 (true) as the result of comparison with "<". When the -r option is not used, sglob_comp() returns 1 or 0 only. When the -r option is used, it returns -1 or 0 only sglob_comp(const void *aa, const void *bb) { ... int rmul = sort_flag & LS_REVERSE_SORT ? -1 : 1; ... else if (sort_flag & LS_TIME_SORT) { #if defined(HAVE_STRUCT_STAT_ST_MTIM) return (rmul * timespeccmp(&as->st_mtim, &bs->st_mtim, <)); The following is about the comparison function of qsort() in man qsort. In man qsort The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. If two members compare as equal, their order in the sorted array is undefined. So, the above sglob_comp() doesn't meet this requirement. It should return -1, 0, or 1. Version-Release number of selected component (if applicable): openssh-8.0p1-5.el8.x86_64 How reproducible: Always Steps to Reproduce: 1. Create three files in /root on any ssh server # cd /root # touch SG0001 wait more than one minute # touch SG0003 wait more than one minute # touch SG0002 NOTE: We can see the difference of the modification time in the "ls -lt" output by waiting more than one minute. 2. connect with sftp from *RHEL8.3 client* # sftp root@<hostname> NOTE: sorting is done in the sftp client side. 3. Run "ls -ltr SG*" Actual results: Sorting with -l option doesn't work. sftp> ls -ltr SG* -rw-r--r-- ? 0 0 0 Dec 22 17:43 SG0003 -rw-r--r-- ? 0 0 0 Dec 22 17:40 SG0001 -rw-r--r-- ? 0 0 0 Dec 22 17:45 SG0002 Expected results: Sorting with -l option works. sftp> ls -ltr SG* -rw-r--r-- ? 0 0 0 Dec 22 17:40 SG0001 -rw-r--r-- ? 0 0 0 Dec 22 17:43 SG0003 -rw-r--r-- ? 0 0 0 Dec 22 17:45 SG0002