libjson-c: backport security fixes
[openwrt/openwrt.git] / package / libs / libjson-c / patches / 004-Issue-599-Fix-the-backwards-check-in-lh_table_insert.patch
1 From 519dfe1591d85432986f9762d41d1a883198c157 Mon Sep 17 00:00:00 2001
2 From: Eric Haszlakiewicz <erh+git@nimenees.com>
3 Date: Sun, 10 May 2020 03:32:19 +0000
4 Subject: [PATCH] Issue #599: Fix the backwards check in
5 lh_table_insert_w_hash() that was preventing adding more than 11 objects. Add
6 a test to check for this too.
7
8 ---
9 linkhash.c | 2 +-
10 tests/test4.c | 29 +++++++++++++++++++++++++++++
11 tests/test4.expected | 1 +
12 3 files changed, 31 insertions(+), 1 deletion(-)
13
14 diff --git a/linkhash.c b/linkhash.c
15 index 51e90b1..f930efd 100644
16 --- a/linkhash.c
17 +++ b/linkhash.c
18 @@ -582,7 +582,7 @@ int lh_table_insert_w_hash(struct lh_table *t, const void *k, const void *v, con
19
20 if (t->count >= t->size * LH_LOAD_FACTOR) {
21 /* Avoid signed integer overflow with large tables. */
22 - int new_size = INT_MAX / 2 < t->size ? t->size * 2 : INT_MAX;
23 + int new_size = (t->size > INT_MAX / 2) ? INT_MAX : (t->size * 2);
24 if (t->size == INT_MAX || lh_table_resize(t, new_size) != 0)
25 return -1;
26 }
27 --
28 2.26.2
29