commands: menu: check return pointer properly
PATCH 1/5 commands: menu: check return pointer properly
The called functions return error codes encoded in the pointer, so the NULL check will never be true.
--- commands/menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
commands/menu.c +1 -1
@@ -83,7 +83,7 @@ static int do_menu_entry_add(struct cmd_menu *cm)else me =menu_add_command_entry (m, cm->description, cm->command, cm->type); -if (!me) +if (IS_ERR (me))return PTR_ERR (me); me->box_state = cm->box_state >0 ?1 :0 ;
Signature · 7 lines
2.7.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/5 ARM: i.MX: iim: fix potential out of bounds array access
The check is off-by-one.
--- arch/arm/mach-imx/iim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-imx/iim.c +1 -1
@@ -196,7 +196,7 @@ int imx_iim_read(unsigned int banknum, int offset, void *buf, int count)if (!imx_iim)return -ENODEV ; -if (banknum >IIM_NUM_BANKS ) +if (banknum >=IIM_NUM_BANKS )return -EINVAL ; bank = iim->bank[banknum];
Signature · 7 lines
2.7.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 3/5 ubifs: fix potential memory leak
In reply to Lucas StachNeed to go through the regular error path in order to free "buf" correctly.
--- fs/ubifs/lprops.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/ubifs/lprops.c +4 -2
@@ -1095,14 +1095,16 @@ static int scan_check_cb(struct ubifs_info *c, lst->empty_lebs +=1 ; lst->total_free += c->leb_size; lst->total_dark +=ubifs_calc_dark (c, c->leb_size); -return LPT_SCAN_CONTINUE ; + ret =LPT_SCAN_CONTINUE ; + goto out; }if (lp->free + lp->dirty == c->leb_size && !(lp->flags &LPROPS_INDEX )) { lst->total_free += lp->free; lst->total_dirty += lp->dirty; lst->total_dark +=ubifs_calc_dark (c, c->leb_size); -return LPT_SCAN_CONTINUE ; + ret =LPT_SCAN_CONTINUE ; + goto out; } sleb =ubifs_scan (c, lnum,0 , buf,0 );
Signature · 7 lines
2.7.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 4/5 ubifs: fix potential NULL ptr dereference
In reply to Lucas Stach--- fs/ubifs/ubifs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ubifs/ubifs.c +1 -1
@@ -479,7 +479,7 @@ out:dbg_gen ("cannot find next direntry, error %d" , err); out_free: -if (file->private_data) +if (file && file->private_data)kfree (file->private_data);if (file)free (file);
Signature · 7 lines
2.7.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 5/5 ubifs: check return pointer properly
In reply to Lucas Stachubifs_iget() returns error codes encoded in the pointer, so the NULL check will never be true.
--- fs/ubifs/ubifs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/ubifs/ubifs.c +4 -4
@@ -533,7 +533,7 @@ static unsigned long ubifs_findfile(struct super_block *sb, const char *filenamereturn 0 ; inode =ubifs_iget (sb, inum); -if (!inode) +if (IS_ERR (inode))return 0 ; ui =ubifs_inode (inode);
@@ -1001,7 +1001,7 @@ static int ubifs_open(struct device_d *dev, FILE *file, const char *filename)return -ENOENT ; inode =ubifs_iget (priv->sb, inum); -if (!inode) +if (IS_ERR (inode))return -ENOENT ; uf =xzalloc (sizeof (*uf));
@@ -1126,7 +1126,7 @@ static DIR *ubifs_opendir(struct device_d *dev, const char *pathname)return NULL ; inode =ubifs_iget (priv->sb, inum); -if (!inode) +if (IS_ERR (inode))return NULL ;ubifs_iput (inode);
@@ -1206,7 +1206,7 @@ static int ubifs_stat(struct device_d *dev, const char *filename, struct stat *sreturn -ENOENT ; inode =ubifs_iget (priv->sb, inum); -if (!inode) +if (IS_ERR (inode))return -ENOENT ; s->st_size = inode->i_size;
Signature · 7 lines
2.7.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
maintainerRe: [PATCH 3/5] ubifs: fix potential memory leak
In reply to Lucas StachQuoted 21 lines · Lucas Stach
Need to go through the regular error path in order to free "buf" correctly.
Signed-off-by Lucas Stach <[email protected]>--- fs/ubifs/lprops.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)fs/ubifs/lprops.c +2
-1@@ -1095,14 +1095,16 @@ static int scan_check_cb(struct ubifs_info *c, lst->empty_lebs +=1 ; lst->total_free += c->leb_size; lst->total_dark +=ubifs_calc_dark (c, c->leb_size); -return LPT_SCAN_CONTINUE ; + ret =LPT_SCAN_CONTINUE ; + goto out; } if (lp->free + lp->dirty == c->leb_size &&
fs/ubifs/lprops.c static int scan_check_cb(struct ubifs_info *c, · line 1110
Quoted 10 lines
fs/ubifs/lprops.c +2
-1!(lp->flags & LPROPS_INDEX)) { lst->total_free += lp->free; lst->total_dirty += lp->dirty; lst->total_dark +=ubifs_calc_dark (c, c->leb_size); -return LPT_SCAN_CONTINUE ; + ret =LPT_SCAN_CONTINUE ; + goto out; } sleb =ubifs_scan (c, lnum,0 , buf,0 );
"buf' is only used after these two if() blocks, so it should simply be allocated afterwards.
The same bug is also present in the kernel, so you might want to send it there aswell.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
maintainerRe: [PATCH 4/5] ubifs: fix potential NULL ptr dereference
In reply to Lucas StachQuoted 10 lines · Lucas Stach
Signed-off-by Lucas Stach <[email protected]>--- fs/ubifs/ubifs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ubifs/ubifs.c +0
-0
fs/ubifs/ubifs.c out: · line 485
Quoted 8 lines
fs/ubifs/ubifs.c +1
-1@@ -479,7 +479,7 @@ out:dbg_gen ("cannot find next direntry, error %d" , err); out_free: -if (file->private_data) +if (file && file->private_data)kfree (file->private_data);if (file)free (file);
We should rather use xzalloc, then we could drop all the if() in the error path.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
maintainerHi Lucas,
I applied all patches from this and the other series I haven't commented on.
Sascha
Quoted 30 lines · Lucas Stach
The called functions return error codes encoded in the pointer, so the NULL check will never be true.
Signed-off-by Lucas Stach <[email protected]>--- commands/menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)commands/menu.c +1
-1@@ -83,7 +83,7 @@ static int do_menu_entry_add(struct cmd_menu *cm)else me =menu_add_command_entry (m, cm->description, cm->command, cm->type); -if (!me) +if (IS_ERR (me))return PTR_ERR (me); me->box_state = cm->box_state >0 ?1 :0 ;Signature · 7 lines
2.7.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox