diff mbox

[U-Boot,5/9] lzo: add a function to check the validity of the header

Message ID 1500570157-24042-6-git-send-email-jjhiblot@ti.com
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Jean-Jacques Hiblot July 20, 2017, 5:02 p.m. UTC
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
---
 include/linux/lzo.h        |  3 +++
 lib/lzo/lzo1x_decompress.c | 21 +++++++++++++++++----
 2 files changed, 20 insertions(+), 4 deletions(-)

Comments

Tom Rini July 24, 2017, 1:21 p.m. UTC | #1
On Thu, Jul 20, 2017 at 07:02:32PM +0200, Jean-Jacques Hiblot wrote:

> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

Reviewed-by: Tom Rini <trini@konsulko.com>
Simon Glass Aug. 3, 2017, 3:25 p.m. UTC | #2
On 20 July 2017 at 11:02, Jean-Jacques Hiblot <jjhiblot@ti.com> wrote:
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
> ---
>  include/linux/lzo.h        |  3 +++
>  lib/lzo/lzo1x_decompress.c | 21 +++++++++++++++++----
>  2 files changed, 20 insertions(+), 4 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox

Patch

diff --git a/include/linux/lzo.h b/include/linux/lzo.h
index 88687fa..8981d04 100644
--- a/include/linux/lzo.h
+++ b/include/linux/lzo.h
@@ -31,6 +31,9 @@  int lzo1x_decompress_safe(const unsigned char *src, size_t src_len,
 int lzop_decompress(const unsigned char *src, size_t src_len,
 		    unsigned char *dst, size_t *dst_len);
 
+/* check if the header is valid (based on magic numbers) */
+bool lzop_is_valid_header(const unsigned char *src);
+
 /*
  * Return values (< 0 = Error)
  */
diff --git a/lib/lzo/lzo1x_decompress.c b/lib/lzo/lzo1x_decompress.c
index ccc90b8..65fef0b 100644
--- a/lib/lzo/lzo1x_decompress.c
+++ b/lib/lzo/lzo1x_decompress.c
@@ -30,16 +30,29 @@  static const unsigned char lzop_magic[] = {
 
 #define HEADER_HAS_FILTER	0x00000800L
 
-static inline const unsigned char *parse_header(const unsigned char *src)
+
+bool lzop_is_valid_header(const unsigned char *src)
 {
-	u16 version;
 	int i;
-
 	/* read magic: 9 first bytes */
 	for (i = 0; i < ARRAY_SIZE(lzop_magic); i++) {
 		if (*src++ != lzop_magic[i])
-			return NULL;
+			return false;
 	}
+	return true;
+}
+
+static inline const unsigned char *parse_header(const unsigned char *src)
+{
+	u16 version;
+	int i;
+
+	if (!lzop_is_valid_header(src))
+		return NULL;
+
+	/* skip header */
+	src += 9;
+
 	/* get version (2bytes), skip library version (2),
 	 * 'need to be extracted' version (2) and
 	 * method (1) */