xref: /OK3568_Linux_fs/buildroot/package/pure-ftpd/0002-pure_strcmp-len-s2-can-be-len-s1.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1From 36c6d268cb190282a2c17106acfd31863121b58e Mon Sep 17 00:00:00 2001
2From: Frank Denis <github@pureftpd.org>
3Date: Mon, 24 Feb 2020 15:19:43 +0100
4Subject: [PATCH] pure_strcmp(): len(s2) can be > len(s1)
5
6Reported by Antonio Morales from GitHub Security Labs, thanks!
7[Retrieved from:
8https://github.com/jedisct1/pure-ftpd/commit/36c6d268cb190282a2c17106acfd31863121b]
9Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
10---
11 src/utils.c | 8 +++++++-
12 1 file changed, 7 insertions(+), 1 deletion(-)
13
14diff --git a/src/utils.c b/src/utils.c
15index f41492d..a7f0381 100644
16--- a/src/utils.c
17+++ b/src/utils.c
18@@ -45,5 +45,11 @@ int pure_memcmp(const void * const b1_, const void * const b2_, size_t len)
19
20 int pure_strcmp(const char * const s1, const char * const s2)
21 {
22-    return pure_memcmp(s1, s2, strlen(s1) + 1U);
23+    const size_t s1_len = strlen(s1);
24+    const size_t s2_len = strlen(s2);
25+
26+    if (s1_len != s2_len) {
27+        return -1;
28+    }
29+    return pure_memcmp(s1, s2, s1_len);
30 }
31