Skip to contentSkip to conversation

btrfs-progs: check: Sanitize the return value for qgroup error

PATCH In review Qu Wenruo 3 participants 3 messages Mar 30, 2020 – Apr 1, 2020 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH 1/1 btrfs-progs: check: Sanitize the return value for qgroup error

[BUG]
btrfs check can return strange return value for shell:
[Inferior 1 (process 48641) exited with code 0213]

					      ^^^^

[CAUSE]
It's caused by the incorrect handling of qgroup error.

qgroup_report_ret can be -117 (-EUCLEAN), using that value with exit() can cause overflow, causing return value not properly recognized.

[FIX]
Fix it by sanitize the return value to 0 or 1.

---
 check/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
check/main.c +1 -1
index 37c5b35a36bd..8e29337c5c23 100644
@@ -10458,7 +10458,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
 			goto out;
 		}
 		if (qgroup_report_ret && (!qgroups_repaired || ret))
-			err |= qgroup_report_ret;
+			err |= !!qgroup_report_ret;
 		ret = 0;
 	} else {
 		fprintf(stderr,
Signature · 1 line
2.26.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 24 lines · Qu Wenruo

[BUG]
btrfs check can return strange return value for shell:
[Inferior 1 (process 48641) exited with code 0213]

					      ^^^^

[CAUSE]
It's caused by the incorrect handling of qgroup error.

qgroup_report_ret can be -117 (-EUCLEAN), using that value with exit() can cause overflow, causing return value not properly recognized.

[FIX]
Fix it by sanitize the return value to 0 or 1.

---
 check/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
check/main.c +0 -0
index 37c5b35a36bd..8e29337c5c23 100644

check/main.c static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv) · line 10461

Quoted 5 lines
check/main.c +1 -1
@@ -10458,7 +10458,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
 			goto out;
 		}
 		if (qgroup_report_ret && (!qgroups_repaired || ret))
-			err |= qgroup_report_ret;
+			err |= !!qgroup_report_ret;

The original code was just "wow". qgroup_report_ret was an ordinary engative error code and it was "ORed" with err ... Just wow...

While this is correct absed on what the function is doing it's awful. WHy can't simply err = ret in every error branch? Err is really used as a boolean and frankly instead of doing err = blah or err = true we have err |= !!blah. Seriously? Was this code being primed for submission to
https://www.ioccc.org/ ?

Sheesh... in any case:

Quoted 4 lines
check/main.c +0 -0
 		ret = 0;
 	} else {
 		fprintf(stderr,
#2 lore raw
In reply to Qu Wenruo
Quoted 8 lines · Qu Wenruo

[BUG]
btrfs check can return strange return value for shell:
[Inferior 1 (process 48641) exited with code 0213]

					      ^^^^

[CAUSE]
It's caused by the incorrect handling of qgroup error.

Quoted 7 lines

qgroup_report_ret can be -117 (-EUCLEAN), using that value with exit() can cause overflow, causing return value not properly recognized.

[FIX]
Fix it by sanitize the return value to 0 or 1.

Added to devel, thanks.