From f69260725ebd17846274c8e526a45087d4c6f0f6 Mon Sep 17 00:00:00 2001 From: CN_SZTL Date: Thu, 23 Apr 2020 04:26:17 +0800 Subject: [PATCH] libubox: backport fixes Signed-off-by: CN_SZTL --- package/libs/libubox/Makefile | 2 +- ...ix-leak-of-memory-pointed-to-by-vars.patch | 38 +++++++++++++ ...ix-leaks-of-memory-pointed-to-by-obj.patch | 56 +++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 package/libs/libubox/patches/0018-jshn-main-fix-leak-of-memory-pointed-to-by-vars.patch create mode 100644 package/libs/libubox/patches/0019-jshn_parse-fix-leaks-of-memory-pointed-to-by-obj.patch diff --git a/package/libs/libubox/Makefile b/package/libs/libubox/Makefile index 4a8df1dd37..c4748d93b0 100644 --- a/package/libs/libubox/Makefile +++ b/package/libs/libubox/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=libubox -PKG_RELEASE=4 +PKG_RELEASE=5 PKG_SOURCE_PROTO:=git PKG_SOURCE_URL=$(PROJECT_GIT)/project/libubox.git diff --git a/package/libs/libubox/patches/0018-jshn-main-fix-leak-of-memory-pointed-to-by-vars.patch b/package/libs/libubox/patches/0018-jshn-main-fix-leak-of-memory-pointed-to-by-vars.patch new file mode 100644 index 0000000000..27a9610901 --- /dev/null +++ b/package/libs/libubox/patches/0018-jshn-main-fix-leak-of-memory-pointed-to-by-vars.patch @@ -0,0 +1,38 @@ +From c42f11cc7c0f0ec6571af06ada6ff0e8882f4fde Mon Sep 17 00:00:00 2001 +From: =?utf8?q?Petr=20=C5=A0tetiar?= +Date: Tue, 19 Nov 2019 12:34:14 +0100 +Subject: [PATCH] jshn: main: fix leak of memory pointed to by 'vars' +MIME-Version: 1.0 +Content-Type: text/plain; charset=utf8 +Content-Transfer-Encoding: 8bit + +Fixes following leak of memory: + + 6,016 bytes in 1 blocks are possibly lost in loss record 1 of 1 + at 0x4C31B25: calloc + by 0x1098F8: main (jshn.c:353) + +Signed-off-by: Petr Å tetiar +--- + jshn.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/jshn.c b/jshn.c +index 2d1748e..00293f2 100644 +--- a/jshn.c ++++ b/jshn.c +@@ -410,8 +410,11 @@ + indent = true; + break; + default: ++ free(vars); + return usage(argv[0]); + } + } ++ ++ free(vars); + return usage(argv[0]); + } +-- +2.20.1 + diff --git a/package/libs/libubox/patches/0019-jshn_parse-fix-leaks-of-memory-pointed-to-by-obj.patch b/package/libs/libubox/patches/0019-jshn_parse-fix-leaks-of-memory-pointed-to-by-obj.patch new file mode 100644 index 0000000000..a2b6cfc9d4 --- /dev/null +++ b/package/libs/libubox/patches/0019-jshn_parse-fix-leaks-of-memory-pointed-to-by-obj.patch @@ -0,0 +1,56 @@ +From cb698e35409b898aedbbc3c673a0055dc1520ef6 Mon Sep 17 00:00:00 2001 +From: =?utf8?q?Petr=20=C5=A0tetiar?= +Date: Tue, 19 Nov 2019 14:09:43 +0100 +Subject: [PATCH 1/1] jshn: jshn_parse: fix leaks of memory pointed to by 'obj' +MIME-Version: 1.0 +Content-Type: text/plain; charset=utf8 +Content-Transfer-Encoding: 8bit + +Fixes following leaks of memory: + + 352 (72 direct, 280 indirect) bytes in 1 blocks are definitely lost in loss record 3 of 3 + at 0x4C31B25: calloc + by 0x5042E1F: json_object_new_array + by 0x5044B02: json_tokener_parse_ex + by 0x5045316: json_tokener_parse_verbose + by 0x504537D: json_tokener_parse + by 0x401AA9: jshn_parse (jshn.c:179) + by 0x401977: main (jshn.c:378) + + 752 (72 direct, 680 indirect) bytes in 1 blocks are definitely lost in loss record 6 of 6 + at 0x4C31B25: calloc + by 0x50424CF: json_object_new_object + by 0x5044B38: json_tokener_parse_ex + by 0x5045316: json_tokener_parse_verbose + by 0x504537D: json_tokener_parse + by 0x401AA9: jshn_parse (jshn.c:179) + by 0x401977: main (jshn.c:380) + +Signed-off-by: Petr Å tetiar +--- + jshn.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/jshn.c b/jshn.c +index 2eebe6c..9639951 100644 +--- a/jshn.c ++++ b/jshn.c +@@ -178,12 +178,15 @@ static int jshn_parse(const char *str) + + obj = json_tokener_parse(str); + if (!obj || json_object_get_type(obj) != json_type_object) { ++ if (obj) ++ json_object_put(obj); + fprintf(stderr, "Failed to parse message data\n"); + return 1; + } + fprintf(stdout, "json_init;\n"); + add_json_object(obj); + fflush(stdout); ++ json_object_put(obj); + + return 0; + } +-- +2.20.1 +