diff options
author | Jean-Jacques Hiblot <jjhiblot@ti.com> | 2017-09-15 12:57:28 +0200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2017-10-05 21:31:04 -0400 |
commit | d753f942ec12e6b5b2db73698aa6c55588053d3a (patch) | |
tree | 57d7bfdd0f8a8f48267bdea1a39584b84cfa1c33 /lib | |
parent | 02035d0086b3f9114463a9b9df38a5618ffe8a04 (diff) | |
download | u-boot-d753f942ec12e6b5b2db73698aa6c55588053d3a.tar.gz u-boot-d753f942ec12e6b5b2db73698aa6c55588053d3a.tar.bz2 u-boot-d753f942ec12e6b5b2db73698aa6c55588053d3a.zip |
lzo: add a function to check the validity of the header
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lzo/lzo1x_decompress.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/lzo/lzo1x_decompress.c b/lib/lzo/lzo1x_decompress.c index ccc90b8ee5..65fef0b0eb 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) */ |