qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qdev-property: Make bit property parsing stricter
@ 2012-01-21 13:43 Jan Kiszka
  2012-01-21 16:36 ` Andreas Färber
  2012-01-27  5:50 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
  0 siblings, 2 replies; 5+ messages in thread
From: Jan Kiszka @ 2012-01-21 13:43 UTC (permalink / raw)
  To: qemu-devel, qemu-trivial; +Cc: Markus Armbruster

By using strncasecmp, we allow for arbitrary characters after the
"on"/"off" string. Fix this by switching to strcasecmp.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 hw/qdev-properties.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 02f0dae..ea3b2df 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -40,9 +40,9 @@ static void qdev_prop_cpy(DeviceState *dev, Property *props, void *src)
 /* Bit */
 static int parse_bit(DeviceState *dev, Property *prop, const char *str)
 {
-    if (!strncasecmp(str, "on", 2))
+    if (!strcasecmp(str, "on"))
         bit_prop_set(dev, prop, true);
-    else if (!strncasecmp(str, "off", 3))
+    else if (!strcasecmp(str, "off"))
         bit_prop_set(dev, prop, false);
     else
         return -EINVAL;
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] qdev-property: Make bit property parsing stricter
  2012-01-21 13:43 [Qemu-devel] [PATCH] qdev-property: Make bit property parsing stricter Jan Kiszka
@ 2012-01-21 16:36 ` Andreas Färber
  2012-01-21 17:07   ` Jan Kiszka
  2012-01-27  5:50 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
  1 sibling, 1 reply; 5+ messages in thread
From: Andreas Färber @ 2012-01-21 16:36 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: qemu-trivial, qemu-devel, Markus Armbruster

Am 21.01.2012 14:43, schrieb Jan Kiszka:
> By using strncasecmp, we allow for arbitrary characters after the
> "on"/"off" string. Fix this by switching to strcasecmp.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>

Reviewed-by: Andreas Färber <afaerber@suse.de>

An alternative might be to increase the char count by one. For a const
char* parameter I see the responsibility for nul-terminating at the
caller though, so this seems right. Did you check all callers?

Andreas

> ---
>  hw/qdev-properties.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
> index 02f0dae..ea3b2df 100644
> --- a/hw/qdev-properties.c
> +++ b/hw/qdev-properties.c
> @@ -40,9 +40,9 @@ static void qdev_prop_cpy(DeviceState *dev, Property *props, void *src)
>  /* Bit */
>  static int parse_bit(DeviceState *dev, Property *prop, const char *str)
>  {
> -    if (!strncasecmp(str, "on", 2))
> +    if (!strcasecmp(str, "on"))
>          bit_prop_set(dev, prop, true);
> -    else if (!strncasecmp(str, "off", 3))
> +    else if (!strcasecmp(str, "off"))
>          bit_prop_set(dev, prop, false);
>      else
>          return -EINVAL;

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] qdev-property: Make bit property parsing stricter
  2012-01-21 16:36 ` Andreas Färber
@ 2012-01-21 17:07   ` Jan Kiszka
  2012-01-24 12:05     ` Markus Armbruster
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Kiszka @ 2012-01-21 17:07 UTC (permalink / raw)
  To: Andreas Färber; +Cc: qemu-trivial, qemu-devel, Markus Armbruster

[-- Attachment #1: Type: text/plain, Size: 798 bytes --]

On 2012-01-21 17:36, Andreas Färber wrote:
> Am 21.01.2012 14:43, schrieb Jan Kiszka:
>> By using strncasecmp, we allow for arbitrary characters after the
>> "on"/"off" string. Fix this by switching to strcasecmp.
>>
>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> 
> Reviewed-by: Andreas Färber <afaerber@suse.de>
> 
> An alternative might be to increase the char count by one. For a const
> char* parameter I see the responsibility for nul-terminating at the
> caller though, so this seems right. Did you check all callers?

For any normal function that takes a char * string without a maximum
length, the responsibility for terminating is on caller side. Also
because we checks against patterns of different length. So we don't need
to jump through hoops here.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] qdev-property: Make bit property parsing stricter
  2012-01-21 17:07   ` Jan Kiszka
@ 2012-01-24 12:05     ` Markus Armbruster
  0 siblings, 0 replies; 5+ messages in thread
From: Markus Armbruster @ 2012-01-24 12:05 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: qemu-trivial, Andreas Färber, qemu-devel

Jan Kiszka <jan.kiszka@web.de> writes:

> On 2012-01-21 17:36, Andreas Färber wrote:
>> Am 21.01.2012 14:43, schrieb Jan Kiszka:
>>> By using strncasecmp, we allow for arbitrary characters after the
>>> "on"/"off" string. Fix this by switching to strcasecmp.
>>>
>>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
>> 
>> Reviewed-by: Andreas Färber <afaerber@suse.de>
>> 
>> An alternative might be to increase the char count by one. For a const
>> char* parameter I see the responsibility for nul-terminating at the
>> caller though, so this seems right. Did you check all callers?
>
> For any normal function that takes a char * string without a maximum
> length, the responsibility for terminating is on caller side. Also
> because we checks against patterns of different length. So we don't need
> to jump through hoops here.

I agree.

Reviewed-by: Markus Armbruster <armbru@redhat.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH] qdev-property: Make bit property parsing stricter
  2012-01-21 13:43 [Qemu-devel] [PATCH] qdev-property: Make bit property parsing stricter Jan Kiszka
  2012-01-21 16:36 ` Andreas Färber
@ 2012-01-27  5:50 ` Stefan Hajnoczi
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2012-01-27  5:50 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: qemu-trivial, qemu-devel, Markus Armbruster

On Sat, Jan 21, 2012 at 02:43:07PM +0100, Jan Kiszka wrote:
> By using strncasecmp, we allow for arbitrary characters after the
> "on"/"off" string. Fix this by switching to strcasecmp.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>  hw/qdev-properties.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)

Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches

Stefan

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-01-27  5:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-21 13:43 [Qemu-devel] [PATCH] qdev-property: Make bit property parsing stricter Jan Kiszka
2012-01-21 16:36 ` Andreas Färber
2012-01-21 17:07   ` Jan Kiszka
2012-01-24 12:05     ` Markus Armbruster
2012-01-27  5:50 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).