Rebase on upstream commit 32611aea6543 See $ cd SELinuxProject/selinux $ git log --pretty=oneline libsepol-3.2..32611aea6543 -- libsepol
64 lines
1.8 KiB
Diff
64 lines
1.8 KiB
Diff
From 19a6ebfa895ce3baa6bd07cb5227556c82f20cb6 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
|
|
Date: Tue, 8 Jun 2021 17:59:01 +0200
|
|
Subject: [PATCH] libsepol: do not allocate memory of size 0
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
In case cats_ebitmap_len() returns 0, do not allocate but quit.
|
|
|
|
Found by clang-analyzer
|
|
|
|
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
|
|
Acked-by: James Carter <jwcart2@gmail.com>
|
|
---
|
|
libsepol/src/kernel_to_cil.c | 5 ++++-
|
|
libsepol/src/kernel_to_conf.c | 5 ++++-
|
|
2 files changed, 8 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/libsepol/src/kernel_to_cil.c b/libsepol/src/kernel_to_cil.c
|
|
index 30a27bf527d5..5aaee6288565 100644
|
|
--- a/libsepol/src/kernel_to_cil.c
|
|
+++ b/libsepol/src/kernel_to_cil.c
|
|
@@ -1034,11 +1034,14 @@ static char *cats_ebitmap_to_str(struct ebitmap *cats, char **val_to_name)
|
|
{
|
|
struct ebitmap_node *node;
|
|
uint32_t i, start, range;
|
|
- char *catsbuf, *p;
|
|
+ char *catsbuf = NULL, *p;
|
|
const char *fmt;
|
|
int len, remaining;
|
|
|
|
remaining = (int)cats_ebitmap_len(cats, val_to_name);
|
|
+ if (remaining == 0) {
|
|
+ goto exit;
|
|
+ }
|
|
catsbuf = malloc(remaining);
|
|
if (!catsbuf) {
|
|
goto exit;
|
|
diff --git a/libsepol/src/kernel_to_conf.c b/libsepol/src/kernel_to_conf.c
|
|
index ffdf179a71f3..cb8e13809d52 100644
|
|
--- a/libsepol/src/kernel_to_conf.c
|
|
+++ b/libsepol/src/kernel_to_conf.c
|
|
@@ -1025,12 +1025,15 @@ static char *cats_ebitmap_to_str(struct ebitmap *cats, char **val_to_name)
|
|
{
|
|
struct ebitmap_node *node;
|
|
uint32_t i, start, range, first;
|
|
- char *catsbuf, *p;
|
|
+ char *catsbuf = NULL, *p;
|
|
const char *fmt;
|
|
char sep;
|
|
int len, remaining;
|
|
|
|
remaining = (int)cats_ebitmap_len(cats, val_to_name);
|
|
+ if (remaining == 0) {
|
|
+ goto exit;
|
|
+ }
|
|
catsbuf = malloc(remaining);
|
|
if (!catsbuf) {
|
|
goto exit;
|
|
--
|
|
2.32.0
|
|
|