Currently when detecting invalid options in option parsing,
some options(e.g. msize) just set errno and allow to continuously
validate other options so that it can detect invalid options
as much as possible and give proper error messages together.
This patch applies same rule to option 'trans' and 'version'
when detecting EINVAL.
Signed-off-by: Chengguang Xu <[email protected]>
---
Changes since v1:
- Do not change behavior when detecting ENOMEM or unrecognized options.
net/9p/client.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/9p/client.c b/net/9p/client.c
index 21e6df1..38b02fb 100644
--- a/net/9p/client.c
+++ b/net/9p/client.c
@@ -199,7 +199,7 @@ static int parse_opts(char *opts, struct p9_client *clnt)
s);
ret = -EINVAL;
kfree(s);
- goto free_and_return;
+ continue;
}
kfree(s);
break;
@@ -217,7 +217,7 @@ static int parse_opts(char *opts, struct p9_client *clnt)
ret = get_protocol_version(s);
if (ret == -EINVAL) {
kfree(s);
- goto free_and_return;
+ continue;
}
kfree(s);
clnt->proto_version = ret;
--
1.8.3.1
Currently when detecting invalid options in option parsing,
some options(e.g. msize) just set errno and allow to continuously
validate other options so that it can detect invalid options
as much as possible and give proper error messages together.
This patch applies same rule to option 'cache' and 'access'
when detecting EINVAL.
Signed-off-by: Chengguang Xu <[email protected]>
---
Changes since v1:
- Do not change behavior when detecting ENOMEM or unrecognized options.
fs/9p/v9fs.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c
index e622f0f..2c7a0ef 100644
--- a/fs/9p/v9fs.c
+++ b/fs/9p/v9fs.c
@@ -309,7 +309,7 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
ret = get_cache_mode(s);
if (ret == -EINVAL) {
kfree(s);
- goto free_and_return;
+ continue;
}
v9ses->cache = ret;
@@ -341,14 +341,14 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
pr_info("Unknown access argument %s\n",
s);
kfree(s);
- goto free_and_return;
+ continue;
}
v9ses->uid = make_kuid(current_user_ns(), uid);
if (!uid_valid(v9ses->uid)) {
ret = -EINVAL;
pr_info("Uknown uid %s\n", s);
kfree(s);
- goto free_and_return;
+ continue;
}
}
--
1.8.3.1
On Tue, 17 Apr 2018 14:45:01 +0800 Chengguang Xu <[email protected]> wrote:
> Currently when detecting invalid options in option parsing,
> some options(e.g. msize) just set errno and allow to continuously
> validate other options so that it can detect invalid options
> as much as possible and give proper error messages together.
>
> This patch applies same rule to option 'trans' and 'version'
> when detecting EINVAL.
>
> ...
A few issues:
> --- a/net/9p/client.c
> +++ b/net/9p/client.c
> @@ -199,7 +199,7 @@ static int parse_opts(char *opts, struct p9_client *clnt)
> s);
> ret = -EINVAL;
> kfree(s);
> - goto free_and_return;
> + continue;
> }
> kfree(s);
> break;
Here we can just do
--- a/net/9p/client.c~net-9p-detecting-invalid-options-as-much-as-possible-fix
+++ a/net/9p/client.c
@@ -198,8 +198,6 @@ static int parse_opts(char *opts, struct
pr_info("Could not find request transport: %s\n",
s);
ret = -EINVAL;
- kfree(s);
- continue;
}
kfree(s);
break;
> @@ -217,7 +217,7 @@ static int parse_opts(char *opts, struct p9_client *clnt)
> ret = get_protocol_version(s);
And here's the patch introduces a bug: if `ret' has value -EINVAL from
an earlier parsing error, this code will overwrite that error code with
zero.
So you'll need to introduce a new temporary variable here. And I
suggest that for future-safety, we permit all error returns from
get_protocol_version(), not just -EINVAL. So something like:
--- a/net/9p/client.c~net-9p-detecting-invalid-options-as-much-as-possible-fix
+++ a/net/9p/client.c
@@ -214,13 +214,12 @@ static int parse_opts(char *opts, struct
"problem allocating copy of version arg\n");
goto free_and_return;
}
- ret = get_protocol_version(s);
- if (ret == -EINVAL) {
- kfree(s);
- continue;
- }
+ pv = get_protocol_version(s);
+ if (pv >= 0)
+ clnt->proto_version = pv;
+ else
+ ret = pv;
kfree(s);
- clnt->proto_version = ret;
break;
default:
continue;
_
Similar changes can be made to patch 2/2.
Thanks for your review, I??ll fix the issue in v3.
> ?? 2018??5??3?գ?????6:32??Andrew Morton <[email protected]> д????
>
> On Tue, 17 Apr 2018 14:45:01 +0800 Chengguang Xu <[email protected]> wrote:
>
>> Currently when detecting invalid options in option parsing,
>> some options(e.g. msize) just set errno and allow to continuously
>> validate other options so that it can detect invalid options
>> as much as possible and give proper error messages together.
>>
>> This patch applies same rule to option 'trans' and 'version'
>> when detecting EINVAL.
>>
>> ...
>
> A few issues:
>
>> --- a/net/9p/client.c
>> +++ b/net/9p/client.c
>> @@ -199,7 +199,7 @@ static int parse_opts(char *opts, struct p9_client *clnt)
>> s);
>> ret = -EINVAL;
>> kfree(s);
>> - goto free_and_return;
>> + continue;
>> }
>> kfree(s);
>> break;
>
> Here we can just do
>
> --- a/net/9p/client.c~net-9p-detecting-invalid-options-as-much-as-possible-fix
> +++ a/net/9p/client.c
> @@ -198,8 +198,6 @@ static int parse_opts(char *opts, struct
> pr_info("Could not find request transport: %s\n",
> s);
> ret = -EINVAL;
> - kfree(s);
> - continue;
> }
> kfree(s);
> break;
>
>> @@ -217,7 +217,7 @@ static int parse_opts(char *opts, struct p9_client *clnt)
>> ret = get_protocol_version(s);
>
> And here's the patch introduces a bug: if `ret' has value -EINVAL from
> an earlier parsing error, this code will overwrite that error code with
> zero.
>
> So you'll need to introduce a new temporary variable here. And I
> suggest that for future-safety, we permit all error returns from
> get_protocol_version(), not just -EINVAL. So something like:
>
> --- a/net/9p/client.c~net-9p-detecting-invalid-options-as-much-as-possible-fix
> +++ a/net/9p/client.c
> @@ -214,13 +214,12 @@ static int parse_opts(char *opts, struct
> "problem allocating copy of version arg\n");
> goto free_and_return;
> }
> - ret = get_protocol_version(s);
> - if (ret == -EINVAL) {
> - kfree(s);
> - continue;
> - }
> + pv = get_protocol_version(s);
> + if (pv >= 0)
> + clnt->proto_version = pv;
> + else
> + ret = pv;
> kfree(s);
> - clnt->proto_version = ret;
> break;
> default:
> continue;
> _
>
>
> Similar changes can be made to patch 2/2.
>