commit 8686d0d40d0084bd6bc8ea88bfd33f41817c878b
Author: Oswald Buddenhagen <[email protected]>
Date: Fri Nov 22 21:00:18 2019 +0100
fix overflows in uint comparisons
src/drv_maildir.c | 4 ++--
src/util.c | 5 ++++-
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/drv_maildir.c b/src/drv_maildir.c
index 639bdbf..239eaae 100644
--- a/src/drv_maildir.c
+++ b/src/drv_maildir.c
@@ -848,8 +848,8 @@ maildir_compare( const void *l, const void *r )
char *ldot, *rdot, *ldot2, *rdot2, *lseq, *rseq;
int ret, llen, rlen;
- if ((ret = lm->uid - rm->uid))
- return ret;
+ if (lm->uid != rm->uid) // Can't subtract, the result might not fit
into signed int.
+ return lm->uid > rm->uid ? 1 : -1;
/* No UID, so sort by arrival date. We should not do this, but we rely
on the suggested unique file name scheme - we have no choice. */
diff --git a/src/util.c b/src/util.c
index f66f564..665bb41 100644
--- a/src/util.c
+++ b/src/util.c
@@ -534,7 +534,10 @@ map_name( const char *arg, char **result, int reserve,
const char *in, const cha
static int
compare_uints( const void *l, const void *r )
{
- return *(const uint *)l - *(const uint *)r;
+ uint li = *(const uint *)l, ri = *(const uint *)r;
+ if (li != ri) // Can't subtract, the result might not fit into signed
int.
+ return li > ri ? 1 : -1;
+ return 0;
}
void
_______________________________________________
isync-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/isync-devel