jfs: add a check to prevent array-index-out-of-bounds
PATCH 1/1 jfs: add a check to prevent array-index-out-of-bounds
When the value of lp is 1 at the end of the iteration in the for loop, lp is modified in the next iteration to a negative value. Add a check to prevent this condition.
--- fs/jfs/jfs_dmap.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/jfs/jfs_dmap.c +6 -0
@@ -2911,6 +2911,12 @@ static void dbAdjTree(dmtree_t *tp, int leafno, int newval, bool is_ctl)*/ tp->dmt_stree[pp] = max; +/* check to prevent negative value of lp on the +* next iteration. +*/ +if (lp ==1 ) +break ; +/* parent becomes leaf for next go-round. */ lp = pp;
Signature · 1 line
2.34.1
Quoted 17 lines · Nihar Chaithanya
When the value of lp is 1 at the end of the iteration in the for loop, lp is modified in the next iteration to a negative value. Add a check to prevent this condition.
Reported-by [email protected]Tested-by [email protected]Signed-off-by Nihar Chaithanya <[email protected]>--- fs/jfs/jfs_dmap.c | 6 ++++++ 1 file changed, 6 insertions(+)fs/jfs/jfs_dmap.c +0
-0
fs/jfs/jfs_dmap.c static void dbAdjTree(dmtree_t *tp, int leafno, int newval, bool is_ctl) · line 2919
Quoted 9 lines
fs/jfs/jfs_dmap.c +6
-0@@ -2911,6 +2911,12 @@ static void dbAdjTree(dmtree_t *tp, int leafno, int newval, bool is_ctl)*/ tp->dmt_stree[pp] = max; +/* check to prevent negative value of lp on the +* next iteration. +*/ +if (lp ==1 ) +break ; +
I'm going to change this a little bit. I think it's a little cleaner to test lp for zero at the top of the loop.
fs/jfs/jfs_dmap.c static void dbAdjTree(dmtree_t *tp, int leafno, int newval, bool is_ctl) · line 2922
Quoted 3 lines
fs/jfs/jfs_dmap.c +0
-0/* parent becomes leaf for next go-round. */ lp = pp;
That and rewording the commit message, I will apply this.
Thanks,
Shaggy