linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] lib: 842: Fix pointer dereferenced before checking
@ 2022-03-25  2:57 Haowen Bai
  0 siblings, 0 replies; only message in thread
From: Haowen Bai @ 2022-03-25  2:57 UTC (permalink / raw)
  To: haren; +Cc: linux-kernel, Haowen Bai

The pointer t is dereferencing comp_ops[c] before c is being
 bound checked. Fix this by assigning comp_ops[c] to t only if
c is safy, otherwise just NULL.

Signed-off-by: Haowen Bai <baihaowen@meizu.com>
---
V1->V2: fix two places that dereferenced before checking
 lib/842/842_compress.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/842/842_compress.c b/lib/842/842_compress.c
index c02baa4..0b47e8b 100644
--- a/lib/842/842_compress.c
+++ b/lib/842/842_compress.c
@@ -222,7 +222,7 @@ static int add_bits(struct sw842_param *p, u64 d, u8 n)
 static int add_template(struct sw842_param *p, u8 c)
 {
 	int ret, i, b = 0;
-	u8 *t = comp_ops[c];
+	u8 *t = c < OPS_MAX ? comp_ops[c] : NULL;
 	bool inv = false;
 
 	if (c >= OPS_MAX)
@@ -379,7 +379,7 @@ static int add_end_template(struct sw842_param *p)
 
 static bool check_template(struct sw842_param *p, u8 c)
 {
-	u8 *t = comp_ops[c];
+	u8 *t = c < OPS_MAX ? comp_ops[c] : NULL;
 	int i, match, b = 0;
 
 	if (c >= OPS_MAX)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-25  2:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-25  2:57 [PATCH V2] lib: 842: Fix pointer dereferenced before checking Haowen Bai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).