]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
lzo: add a function to check the validity of the header
authorJean-Jacques Hiblot <jjhiblot@ti.com>
Fri, 15 Sep 2017 10:57:28 +0000 (12:57 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 6 Oct 2017 01:31:04 +0000 (21:31 -0400)
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
include/linux/lzo.h
lib/lzo/lzo1x_decompress.c

index 88687faba10bb9ed9d4862142f5161ec0837a8d2..8981d04f96c9b3fdf260568d5af264b11baea4b0 100644 (file)
@@ -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)
  */
index ccc90b8ee53fe8097d26f20d31b34dface2413b1..65fef0b0eb90591d2c03e6acaf8c267e7b2c9021 100644 (file)
@@ -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) */