From: Michael Tokarev <mjt@tls.msk.ru>
To: "Alex Bennée" <alex.bennee@linaro.org>,
zhanghailiang <zhang.zhanghailiang@huawei.com>
Cc: qemu-trivial@nongnu.org, armbru@redhat.com, kraxel@redhat.com,
qemu-devel@nongnu.org, peter.huangpeng@huawei.com
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH v3 1/5] qemu-char: fix parameter check in some qemu_chr_parse_* functions
Date: Wed, 05 Nov 2014 10:05:58 +0300 [thread overview]
Message-ID: <5459CC56.1030109@msgid.tls.msk.ru> (raw)
In-Reply-To: <874mufumgk.fsf@linaro.org>
04.11.2014 16:25, Alex Bennée wrote:
> zhanghailiang <zhang.zhanghailiang@huawei.com> writes:
>
>> For some qemu_chr_parse_* functions, we just check whether the parameter
>> is NULL or not, but do not check if it is empty.
>>
>> For example:
>> qemu-system-x86_64 -chardev pipe,id=id,path=
>> It will pass the check of NULL but will not find the error until
>> trying to open it, while essentially missing and empty parameter
>> is the same thing.
>>
>> So check the parameters for emptiness too, and avoid emptiness
>> check at open time.
>>
>> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
>> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
>> ---
>> qemu-char.c | 15 +++++----------
>> 1 file changed, 5 insertions(+), 10 deletions(-)
>>
>> diff --git a/qemu-char.c b/qemu-char.c
>> index bd0709b..a09bbf6 100644
>> --- a/qemu-char.c
>> +++ b/qemu-char.c
>> @@ -1084,11 +1084,6 @@ static CharDriverState *qemu_chr_open_pipe(ChardevHostdev *opts)
>> char filename_out[CHR_MAX_FILENAME_SIZE];
>> const char *filename = opts->device;
>>
>> - if (filename == NULL) {
>> - fprintf(stderr, "chardev: pipe: no filename given\n");
>> - return NULL;
>> - }
>> -
>
> You seem to have dropped a check here, are you sure all avenues into
> this code have validated filename? What if a new function gets added?
Yes, the code first calls parse_pipe() and only after it is
successfully completed, it calls open_pipe(). I don't see
a good reason for having assert here.
> At a minimum I'd replace it with a g_assert(filename) to make the
> calling contract clear.
This is an internal set of APIs for a chr device, each kind is
having a pair of functions which are called in order (first parse,
next open), -- _that_ is the contract.
[]
> All this boilerplate checking makes me think that either the qemu_opt
> machinery should be ensuring we get a valid option string?
Might be a good idea, yes, but that'd be a huge change, since that
should be done in a lot of places, and in many cases we can't
express our rules easily (eg, only one of two parameters should
be present). I think at this stage adding simple checks to
_parse functions is the way to go, and it is easy to read too.
Thanks,
/mjt
WARNING: multiple messages have this Message-ID (diff)
From: Michael Tokarev <mjt@tls.msk.ru>
To: "Alex Bennée" <alex.bennee@linaro.org>,
zhanghailiang <zhang.zhanghailiang@huawei.com>
Cc: qemu-trivial@nongnu.org, armbru@redhat.com, kraxel@redhat.com,
qemu-devel@nongnu.org, peter.huangpeng@huawei.com
Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH v3 1/5] qemu-char: fix parameter check in some qemu_chr_parse_* functions
Date: Wed, 05 Nov 2014 10:05:58 +0300 [thread overview]
Message-ID: <5459CC56.1030109@msgid.tls.msk.ru> (raw)
In-Reply-To: <874mufumgk.fsf@linaro.org>
04.11.2014 16:25, Alex Bennée wrote:
> zhanghailiang <zhang.zhanghailiang@huawei.com> writes:
>
>> For some qemu_chr_parse_* functions, we just check whether the parameter
>> is NULL or not, but do not check if it is empty.
>>
>> For example:
>> qemu-system-x86_64 -chardev pipe,id=id,path=
>> It will pass the check of NULL but will not find the error until
>> trying to open it, while essentially missing and empty parameter
>> is the same thing.
>>
>> So check the parameters for emptiness too, and avoid emptiness
>> check at open time.
>>
>> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
>> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
>> ---
>> qemu-char.c | 15 +++++----------
>> 1 file changed, 5 insertions(+), 10 deletions(-)
>>
>> diff --git a/qemu-char.c b/qemu-char.c
>> index bd0709b..a09bbf6 100644
>> --- a/qemu-char.c
>> +++ b/qemu-char.c
>> @@ -1084,11 +1084,6 @@ static CharDriverState *qemu_chr_open_pipe(ChardevHostdev *opts)
>> char filename_out[CHR_MAX_FILENAME_SIZE];
>> const char *filename = opts->device;
>>
>> - if (filename == NULL) {
>> - fprintf(stderr, "chardev: pipe: no filename given\n");
>> - return NULL;
>> - }
>> -
>
> You seem to have dropped a check here, are you sure all avenues into
> this code have validated filename? What if a new function gets added?
Yes, the code first calls parse_pipe() and only after it is
successfully completed, it calls open_pipe(). I don't see
a good reason for having assert here.
> At a minimum I'd replace it with a g_assert(filename) to make the
> calling contract clear.
This is an internal set of APIs for a chr device, each kind is
having a pair of functions which are called in order (first parse,
next open), -- _that_ is the contract.
[]
> All this boilerplate checking makes me think that either the qemu_opt
> machinery should be ensuring we get a valid option string?
Might be a good idea, yes, but that'd be a huge change, since that
should be done in a lot of places, and in many cases we can't
express our rules easily (eg, only one of two parameters should
be present). I think at this stage adding simple checks to
_parse functions is the way to go, and it is easy to read too.
Thanks,
/mjt
next prev parent reply other threads:[~2014-11-05 7:06 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-04 10:50 [Qemu-trivial] [PATCH v3 0/5] Trivial patch about qemu-char zhanghailiang
2014-11-04 10:50 ` [Qemu-devel] " zhanghailiang
2014-11-04 10:50 ` [Qemu-trivial] [PATCH v3 1/5] qemu-char: fix parameter check in some qemu_chr_parse_* functions zhanghailiang
2014-11-04 10:50 ` [Qemu-devel] " zhanghailiang
2014-11-04 13:25 ` [Qemu-trivial] " Alex Bennée
2014-11-04 13:25 ` Alex Bennée
2014-11-05 7:05 ` Michael Tokarev [this message]
2014-11-05 7:05 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-11-05 12:19 ` [Qemu-trivial] [Qemu-devel] " zhanghailiang
2014-11-05 12:19 ` [Qemu-devel] [Qemu-trivial] " zhanghailiang
2014-11-05 13:28 ` [Qemu-trivial] [Qemu-devel] " Alex Bennée
2014-11-05 13:28 ` [Qemu-devel] [Qemu-trivial] " Alex Bennée
2014-11-04 10:50 ` [Qemu-trivial] [PATCH v3 2/5] spice-qemu-char: fix parameter checks in " zhanghailiang
2014-11-04 10:50 ` [Qemu-devel] " zhanghailiang
2014-11-04 13:27 ` [Qemu-trivial] " Alex Bennée
2014-11-04 13:27 ` Alex Bennée
2014-11-04 10:50 ` [Qemu-trivial] [PATCH v3 3/5] qemu-char: fix incorrect state in error message zhanghailiang
2014-11-04 10:50 ` [Qemu-devel] " zhanghailiang
2014-11-04 13:31 ` [Qemu-trivial] " Alex Bennée
2014-11-04 13:31 ` Alex Bennée
2014-11-05 7:08 ` [Qemu-trivial] " Michael Tokarev
2014-11-05 7:08 ` [Qemu-devel] " Michael Tokarev
2014-11-04 10:50 ` [Qemu-trivial] [PATCH v3 4/5] qemu-char: convert some open functions to use Error API zhanghailiang
2014-11-04 10:50 ` [Qemu-devel] " zhanghailiang
2014-11-04 13:39 ` [Qemu-trivial] " Alex Bennée
2014-11-04 13:39 ` Alex Bennée
2014-11-05 7:15 ` [Qemu-trivial] " Michael Tokarev
2014-11-05 7:15 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-11-05 9:08 ` [Qemu-trivial] [Qemu-devel] " Markus Armbruster
2014-11-05 9:08 ` [Qemu-devel] [Qemu-trivial] " Markus Armbruster
2014-11-04 10:50 ` [Qemu-trivial] [PATCH v3 5/5] spice-qemu-char: convert some " zhanghailiang
2014-11-04 10:50 ` [Qemu-devel] " zhanghailiang
2014-11-04 13:41 ` [Qemu-trivial] " Alex Bennée
2014-11-04 13:41 ` Alex Bennée
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=5459CC56.1030109@msgid.tls.msk.ru \
--to=mjt@tls.msk.ru \
--cc=alex.bennee@linaro.org \
--cc=armbru@redhat.com \
--cc=kraxel@redhat.com \
--cc=peter.huangpeng@huawei.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=zhang.zhanghailiang@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.