summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2021-01-08 02:44:15 +0000
committerDamien Miller <djm@cvs.openbsd.org>2021-01-08 02:44:15 +0000
commitdda383dd0815eb819931eb80a855a9c05de9a752 (patch)
tree033560004579c93ad0849562b925aaaf9431c106 /usr.bin
parentb4092bc77232336d50adcff6d884d31e312b6256 (diff)
don't try to use timespeccmp(3) directly as a qsort(3) comparison
function - it returns 0/1 and not the -1/0/1 that qsort expectes. fixes sftp "ls -ltr" under some circumstances. Based on patch by Masahiro Matsuya via bz3248.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/ssh/sftp.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/usr.bin/ssh/sftp.c b/usr.bin/ssh/sftp.c
index 8c3fe96f101..1f2a2ba0107 100644
--- a/usr.bin/ssh/sftp.c
+++ b/usr.bin/ssh/sftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp.c,v 1.205 2020/12/04 02:41:10 djm Exp $ */
+/* $OpenBSD: sftp.c,v 1.206 2021/01/08 02:44:14 djm Exp $ */
/*
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
*
@@ -867,9 +867,12 @@ sglob_comp(const void *aa, const void *bb)
#define NCMP(a,b) (a == b ? 0 : (a < b ? 1 : -1))
if (sort_flag & LS_NAME_SORT)
return (rmul * strcmp(ap, bp));
- else if (sort_flag & LS_TIME_SORT)
- return (rmul * timespeccmp(&as->st_mtim, &bs->st_mtim, <));
- else if (sort_flag & LS_SIZE_SORT)
+ else if (sort_flag & LS_TIME_SORT) {
+ if (timespeccmp(&as->st_mtim, &bs->st_mtim, ==))
+ return 0;
+ return timespeccmp(&as->st_mtim, &bs->st_mtim, <) ?
+ rmul : -rmul;
+ } else if (sort_flag & LS_SIZE_SORT)
return (rmul * NCMP(as->st_size, bs->st_size));
fatal("Unknown ls sort type");