Skip to contentSkip to conversation

Prevent entering an infinite loop when i is 0

PATCH In review liujinbao1 3 participants 3 messages Aug 22, 2024 EROFS file system

lore
Share & tools
lore

liujinbao1

author
#0 lore raw

PATCH 1/1 Prevent entering an infinite loop when i is 0

From: liujinbao1 <[email protected]>

When i=0 and err is not equal to 0,
the while(-1) loop will enter into an
infinite loop. This patch avoids this issue.

---
 fs/erofs/decompressor.c | 2 ++
 1 file changed, 2 insertions(+)
fs/erofs/decompressor.c +2 -0
index c2253b6a5416..1b2b8cc7911c 100644
@@ -539,6 +539,8 @@ int __init z_erofs_init_decompressor(void)
 	for (i = 0; i < Z_EROFS_COMPRESSION_MAX; ++i) {
 		err = z_erofs_decomp[i] ? z_erofs_decomp[i]->init() : 0;
 		if (err) {
+			if (!i)
+				return err;
 			while (--i)
 				if (z_erofs_decomp[i])
 					z_erofs_decomp[i]->exit();
Signature · 1 line
2.25.1
#1 lore raw

Hi,

Quoted 5 lines · On 2024/8/22 14:27, liujinbao1 wrote:

From: liujinbao1 <[email protected]>

When i=0 and err is not equal to 0,
the while(-1) loop will enter into an
infinite loop. This patch avoids this issue.

Missing your Signed-off-by here.

Quoted 9 lines
---
  fs/erofs/decompressor.c | 2 ++
  1 file changed, 2 insertions(+)
fs/erofs/decompressor.c +0 -0
index c2253b6a5416..1b2b8cc7911c 100644

fs/erofs/decompressor.c int __init z_erofs_init_decompressor(void) · line 546

Quoted 8 lines
fs/erofs/decompressor.c +2 -0
@@ -539,6 +539,8 @@ int __init z_erofs_init_decompressor(void)
  	for (i = 0; i < Z_EROFS_COMPRESSION_MAX; ++i) {
  		err = z_erofs_decomp[i] ? z_erofs_decomp[i]->init() : 0;
  		if (err) {
+			if (!i)
+				return err;
  			while (--i)
  				if (z_erofs_decomp[i])
  					z_erofs_decomp[i]->exit();

Thanks for catching this, how about the following diff (space-demaged).

If it looks good to you, could you please send another version?

fs/erofs/decompressor.c +3 -5
index c2253b6a5416..c9b2bc1309d2 100644
@@ -534,18 +534,16 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb)
 
 int __init z_erofs_init_decompressor(void)
 {
-       int i, err;
+       int i, err = 0;
 
        for (i = 0; i < Z_EROFS_COMPRESSION_MAX; ++i) {
                err = z_erofs_decomp[i] ? z_erofs_decomp[i]->init() : 0;
-               if (err) {
+               if (err && i)
                        while (--i)
                                if (z_erofs_decomp[i])
                                        z_erofs_decomp[i]->exit();
-                       return err;
-               }
        }
-       return 0;
+       return err;
 }
#2 lore raw
Quoted 32 lines

Hi,

Quoted 5 lines · On 2024/8/22 14:27, liujinbao1 wrote:

From: liujinbao1 <[email protected]>

When i=0 and err is not equal to 0,
the while(-1) loop will enter into an
infinite loop. This patch avoids this issue.

Missing your Signed-off-by here.

Quoted 9 lines
---
  fs/erofs/decompressor.c | 2 ++
  1 file changed, 2 insertions(+)
fs/erofs/decompressor.c index renamed from fs/erofs/decompressor.c +0 -0

c2253b6a5416..1b2b8cc7911c 100644

fs/erofs/decompressor.c int __init z_erofs_init_decompressor(void) · line 546

Quoted 8 lines
fs/erofs/decompressor.c +2 -0
@@ -539,6 +539,8 @@ int __init z_erofs_init_decompressor(void)
      for (i = 0; i < Z_EROFS_COMPRESSION_MAX; ++i) {
              err = z_erofs_decomp[i] ? z_erofs_decomp[i]->init() : 0;
              if (err) {
+                     if (!i)
+                             return err;
                      while (--i)
                              if (z_erofs_decomp[i])
                                      z_erofs_decomp[i]->exit();

Thanks for catching this, how about the following diff (space-demaged).

Quoted 1 line

If it looks good to you, could you please send another version?

Sure, I can do that.

Quoted 14 lines
fs/erofs/decompressor.c +2 -2
@@ -534,18 +534,16 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb)
 
 int __init z_erofs_init_decompressor(void)
 {
-       int i, err;
+       int i, err = 0;
 
        for (i = 0; i < Z_EROFS_COMPRESSION_MAX; ++i) {
                err = z_erofs_decomp[i] ? z_erofs_decomp[i]->init() : 0;
-               if (err) {
+               if (err && i)

fs/erofs/decompressor.c int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb) · line 548

Quoted 10 lines
fs/erofs/decompressor.c +1 -3
                        while (--i)
                                if (z_erofs_decomp[i])
                                        z_erofs_decomp[i]->exit();
-                       return err;
-               }
        }
-       return 0;
+       return err;
 }
 

#/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#