From: Nikolay Borisov <nborisov@suse.com>
To: Qu Wenruo <wqu@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs-progs: check: Sanitize the return value for qgroup error
Date: Mon, 30 Mar 2020 12:15:25 +0300 [thread overview]
Message-ID: <6cb9b622-35eb-bf4d-2e84-1c3a99ed455e@suse.com> (raw)
In-Reply-To: <20200330070159.50077-1-wqu@suse.com>
On 30.03.20 г. 10:01 ч., Qu Wenruo wrote:
> [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.
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> check/main.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/check/main.c b/check/main.c
> index 37c5b35a36bd..8e29337c5c23 100644
> --- a/check/main.c
> +++ b/check/main.c
> @@ -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:
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
> ret = 0;
> } else {
> fprintf(stderr,
>
next prev parent reply other threads:[~2020-03-30 9:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-30 7:01 [PATCH] btrfs-progs: check: Sanitize the return value for qgroup error Qu Wenruo
2020-03-30 9:15 ` Nikolay Borisov [this message]
2020-04-01 17:57 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6cb9b622-35eb-bf4d-2e84-1c3a99ed455e@suse.com \
--to=nborisov@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=wqu@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox