[U-Boot] [PATCH 1/3] ubifs: BUG realpath string must be ended with NULL

If the memory used to copy the link_name is "dirty" the string wont be ended with NULL, throwing out multiple memory bugs.
Signed-off-by: Ricardo Ribalda Delgado ricardo.ribalda@uam.es --- v3: link_make -> link_name
fs/ubifs/ubifs.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c index 32f9ff8..427d84a 100644 --- a/fs/ubifs/ubifs.c +++ b/fs/ubifs/ubifs.c @@ -641,6 +641,7 @@ int ubifs_load(char *filename, u32 addr, u32 size) ui = ubifs_inode(inode); if (((inode->i_mode & S_IFMT) == S_IFLNK) && ui->data_len) { memcpy(link_name, ui->data, ui->data_len); + link_name[ui->data_len] = '\0'; printf("%s is linked to %s!\n", filename, link_name); ubifs_iput(inode);

Separate gunzip in
gunzip: Find the end of the header and call zunzip. zunzip: Inflate gunzip block without header.
UBI fs blocks can be compresed in lzo, zlib or no-compression. The current implementation of u-boot supported all the compressions but there was a bug in the implementation of the zlib blocks.
UBIFS's Zlib blocks do not have header but they were compressed using gunzip, a function used to decompress gunzip files/sectors with a header.
This patch adds a new function zunzip that uncompress a zlib block with no header.
Signed-off-by: Ricardo Ribalda Delgado ricardo.ribalda@uam.es --- v2-> rename to patch 2/3 lib_generic/gunzip.c | 27 ++++++++++++++++++++------- 1 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/lib_generic/gunzip.c b/lib_generic/gunzip.c index 01a4031..d59a448 100644 --- a/lib_generic/gunzip.c +++ b/lib_generic/gunzip.c @@ -39,6 +39,8 @@ int gunzip(void *, int, unsigned char *, unsigned long *); void *zalloc(void *, unsigned, unsigned); void zfree(void *, void *, unsigned); +int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, + int stoponerr, int offset);
void *zalloc(void *x, unsigned items, unsigned size) { @@ -59,8 +61,7 @@ void zfree(void *x, void *addr, unsigned nb)
int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp) { - z_stream s; - int r, i, flags; + int i, flags;
/* skip header */ i = 10; @@ -84,6 +85,18 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp) return (-1); }
+ return zunzip(dst, dstlen, src, lenp, 1, i); +} + +/* + * Uncompress blocks compressed with zlib without headers + */ +int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, + int stoponerr, int offset) +{ + z_stream s; + int r; + s.zalloc = zalloc; s.zfree = zfree; #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) @@ -95,14 +108,14 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp) r = inflateInit2(&s, -MAX_WBITS); if (r != Z_OK) { printf ("Error: inflateInit2() returned %d\n", r); - return (-1); + return -1; } - s.next_in = src + i; - s.avail_in = *lenp - i; + s.next_in = src + offset; + s.avail_in = *lenp - offset; s.next_out = dst; s.avail_out = dstlen; r = inflate(&s, Z_FINISH); - if (r != Z_STREAM_END) { + if ((r != Z_STREAM_END) && (stoponerr==1)) { printf ("Error: inflate() returned %d\n", r); inflateEnd(&s); return (-1); @@ -110,5 +123,5 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp) *lenp = s.next_out - (unsigned char *) dst; inflateEnd(&s);
- return (0); + return 0; }

Blocks compressed with zlib dont have the full gzip header.
Without this patch, block compressed with zlib cannot be readed!
Signed-off-by: Ricardo Ribalda Delgado ricardo.ribalda@uam.es --- v3: Move the prototype to the header file
fs/ubifs/ubifs.c | 5 +++-- fs/ubifs/ubifs.h | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c index 427d84a..91fc574 100644 --- a/fs/ubifs/ubifs.c +++ b/fs/ubifs/ubifs.c @@ -24,6 +24,7 @@ */
#include "ubifs.h" +#include <u-boot/zlib.h>
#if !defined(CONFIG_SYS_64BIT_VSPRINTF) #warning Please define CONFIG_SYS_64BIT_VSPRINTF for correct output! @@ -34,14 +35,14 @@ DECLARE_GLOBAL_DATA_PTR; /* compress.c */
/* - * We need a wrapper for gunzip() because the parameters are + * We need a wrapper for zunzip() because the parameters are * incompatible with the lzo decompressor. */ static int gzip_decompress(const unsigned char *in, size_t in_len, unsigned char *out, size_t *out_len) { unsigned long len = in_len; - return gunzip(out, *out_len, (unsigned char *)in, &len); + return zunzip(out, *out_len, (unsigned char *)in, &len, 0, 0); }
/* Fake description object for the "none" compressor */ diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index 91351de..43865aa 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h @@ -2172,6 +2172,7 @@ int ubifs_decompress(const void *buf, int len, void *out, int *out_len, /* todo: Move these to a common U-Boot header */ int lzo1x_decompress_safe(const unsigned char *in, size_t in_len, unsigned char *out, size_t *out_len); -int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
+int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, + int stoponerr, int offset); #endif /* !__UBIFS_H__ */
participants (1)
-
Ricardo Ribalda Delgado