qdev: factor out qdev_print_devinfo.
PATCH 1/2 qdev: factor out qdev_print_devinfo.
--- hw/qdev.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-)
hw/qdev.c +18 -1
@@ -105,6 +105,21 @@ DeviceState *qdev_create(BusState *bus, const char *name)return dev; } +static int qdev_print_devinfo (DeviceInfo *info,char *dest,int len) +{ +int pos =0 ; + + pos +=snprintf (dest+pos, len-pos,"name \"%s\", bus %s" , + info->name, info->bus_info->name); +if (info->alias) + pos +=snprintf (dest+pos, len-pos,", alias \"%s\"" , info->alias); +if (info->desc) + pos +=snprintf (dest+pos, len-pos,", desc \"%s\"" , info->desc); +if (info->no_user) + pos +=snprintf (dest+pos, len-pos,", no-user" ); +return pos; +} +DeviceState *qdev_device_add (const char *cmdline) {DeviceInfo *info;
@@ -120,8 +135,10 @@ DeviceState *qdev_device_add(const char *cmdline)return NULL ; }if (strcmp (driver,"?" ) ==0 ) { +char msg[256 ];for (info = device_info_list; info !=NULL ; info = info->next) { -fprintf (stderr,"name \"%s\", bus %s\n" , info->name, info->bus_info->name); +qdev_print_devinfo (info, msg,sizeof (msg)); +fprintf (stderr,"%s\n" , msg); }return NULL ; }
Signature · 1 line
1.6.2.5
PATCH 2/2 qdev/core: add monitor command to list all drivers
--- hw/qdev.c | 11 +++++++++++ hw/qdev.h | 1 + monitor.c | 2 ++ 3 files changed, 14 insertions(+), 0 deletions(-)
hw/qdev.c +11 -0
@@ -590,3 +590,14 @@ void do_info_qtree(Monitor *mon)if (main_system_bus)qbus_print (mon, main_system_bus,0 ); } + +void do_info_qdrv (Monitor *mon) +{ +DeviceInfo *info; +char msg[256 ]; + +for (info = device_info_list; info !=NULL ; info = info->next) { +qdev_print_devinfo (info, msg,sizeof (msg)); +monitor_printf (mon,"%s\n" , msg); + } +}
hw/qdev.h +1 -0
@@ -143,6 +143,7 @@ BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name);/*** monitor commands ***/ void do_info_qtree (Monitor *mon); +void do_info_qdrv (Monitor *mon);/*** qdev-properties.c ***/
monitor.c +2 -0
@@ -1882,6 +1882,8 @@ static const mon_cmd_t info_cmds[] = { "", "show balloon information" }, {"qtree" ,"" , do_info_qtree, "", "show device tree" }, + { "qdrv", "", do_info_qdrv, + "", "show qdev driver list" }, { NULL, NULL, }, };
Signature · 1 line
1.6.2.5
Re: [Qemu-devel] [PATCH 2/2] qdev/core: add monitor command to list all drivers
Quoted 6 lines · Gerd Hoffmann
monitor.c +0
-0
monitor.c static const mon_cmd_t info_cmds[] = { · line 1889
Quoted 8 lines
monitor.c +2
-0@@ -1882,6 +1882,8 @@ static const mon_cmd_t info_cmds[] = { "", "show balloon information" }, {"qtree" ,"" , do_info_qtree, "", "show device tree" }, + { "qdrv", "", do_info_qdrv, + "", "show qdev driver list" }, { NULL, NULL, }, };
Drivers are guest things. You're listing device models, not drivers.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [Qemu-devel] [PATCH 2/2] qdev/core: add monitor command to list all drivers
Quoted 16 lines · Avi Kivity
monitor.c static const mon_cmd_t info_cmds[] = { · line 1888
Quoted 13 lines · Gerd Hoffmann
monitor.c +2
-0@@ -1882,6 +1882,8 @@ static const mon_cmd_t info_cmds[] = { "", "show balloon information" }, {"qtree" ,"" , do_info_qtree, "", "show device tree" }, + { "qdrv", "", do_info_qdrv, + "", "show qdev driver list" }, { NULL, NULL, }, };Drivers are guest things. You're listing device models, not drivers.
Strictly speaking you are correct. But qemu is quite sloppy here and calls the device models drivers (almost?) everythere, so I'd tend to stick with it for consistency ...
cheers,
Gerd
Re: [Qemu-devel] [PATCH 2/2] qdev/core: add monitor command to list all drivers
Quoted 18 lines · Gerd Hoffmann
Quoted 16 lines · Avi Kivity
monitor.c static const mon_cmd_t info_cmds[] = { · line 1888
Quoted 13 lines · Gerd Hoffmann
monitor.c +2
-0@@ -1882,6 +1882,8 @@ static const mon_cmd_t info_cmds[] = { "", "show balloon information" }, {"qtree" ,"" , do_info_qtree, "", "show device tree" }, + { "qdrv", "", do_info_qdrv, + "", "show qdev driver list" }, { NULL, NULL, }, };Drivers are guest things. You're listing device models, not drivers.
Quoted 1 line
Strictly speaking you are correct. But qemu is quite sloppy here and calls the device models drivers (almost?) everythere, so I'd tend to stick with it for consistency ...
Consistently incorrect?
Given that it's an external ABI, let's not be sloppy here.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 18 lines · Gerd Hoffmann
Signed-off-by Gerd Hoffmann <[email protected]>--- hw/qdev.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-)hw/qdev.c +5
-0@@ -105,6 +105,21 @@ DeviceState *qdev_create(BusState *bus, const char *name)return dev; } +static int qdev_print_devinfo (DeviceInfo *info,char *dest,int len) +{ +int pos =0 ; + + pos += snprintf(dest+pos, len-pos, "name \"%s\", bus %s",
hw/qdev.c DeviceState *qdev_create(BusState *bus, const char *name) · line 122
Quoted 10 lines
hw/qdev.c +10
-0+ info->name, info->bus_info->name); +if (info->alias) + pos +=snprintf (dest+pos, len-pos,", alias \"%s\"" , info->alias); +if (info->desc) + pos +=snprintf (dest+pos, len-pos,", desc \"%s\"" , info->desc); +if (info->no_user) + pos +=snprintf (dest+pos, len-pos,", no-user" ); +return pos; +} +
Isn't len-pos vulnerable to underflow here? The formal parameter type is size_t...
[...]
Quoted 34 lines · Markus Armbruster
Quoted 18 lines · Gerd Hoffmann
Signed-off-by Gerd Hoffmann<[email protected]>--- hw/qdev.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-)hw/qdev.c +5
-0@@ -105,6 +105,21 @@ DeviceState *qdev_create(BusState *bus, const char *name)return dev; } +static int qdev_print_devinfo (DeviceInfo *info,char *dest,int len) +{ +int pos =0 ; + + pos += snprintf(dest+pos, len-pos, "name \"%s\", bus %s",hw/qdev.c DeviceState *qdev_create(BusState *bus, const char *name) · line 122
Quoted 10 lines
hw/qdev.c +10
-0+ info->name, info->bus_info->name); +if (info->alias) + pos +=snprintf (dest+pos, len-pos,", alias \"%s\"" , info->alias); +if (info->desc) + pos +=snprintf (dest+pos, len-pos,", desc \"%s\"" , info->desc); +if (info->no_user) + pos +=snprintf (dest+pos, len-pos,", no-user" ); +return pos; +} +Isn't len-pos vulnerable to underflow here? The formal parameter type is
size_t...
Quoted 1 line
[...]
Huh? You mean you want be able to pass a buffer larger than 2^31 to that function?
cheers
Gerd
Quoted 35 lines · Gerd Hoffmann
Quoted 34 lines · Markus Armbruster
Quoted 18 lines · Gerd Hoffmann
Signed-off-by Gerd Hoffmann<[email protected]>--- hw/qdev.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-)hw/qdev.c +5
-0@@ -105,6 +105,21 @@ DeviceState *qdev_create(BusState *bus, const char *name)return dev; } +static int qdev_print_devinfo (DeviceInfo *info,char *dest,int len) +{ +int pos =0 ; + + pos += snprintf(dest+pos, len-pos, "name \"%s\", bus %s",hw/qdev.c DeviceState *qdev_create(BusState *bus, const char *name) · line 122
Quoted 10 lines
hw/qdev.c +10
-0+ info->name, info->bus_info->name); +if (info->alias) + pos +=snprintf (dest+pos, len-pos,", alias \"%s\"" , info->alias); +if (info->desc) + pos +=snprintf (dest+pos, len-pos,", desc \"%s\"" , info->desc); +if (info->no_user) + pos +=snprintf (dest+pos, len-pos,", no-user" ); +return pos; +} +Isn't len-pos vulnerable to underflow here? The formal parameter type is
size_t...
Quoted 7 lines
Quoted 1 line
[...]
Huh? You mean you want be able to pass a buffer larger than 2^31 to that function?
cheers
Gerd
snprintf() returns length of output. This may exceed its buffer size argument. Therefore, pos can grow beyond len, and then len-pos becomes negative. Parameter passing casts that to size_t, and snprintf() happily writes beyond the buffer.
Quoted 37 lines · Markus Armbruster
Quoted 35 lines · Gerd Hoffmann
Quoted 34 lines · Markus Armbruster
Quoted 18 lines · Gerd Hoffmann
Signed-off-by Gerd Hoffmann<[email protected]>--- hw/qdev.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-)hw/qdev.c +5
-0@@ -105,6 +105,21 @@ DeviceState *qdev_create(BusState *bus, const char *name)return dev; } +static int qdev_print_devinfo (DeviceInfo *info,char *dest,int len) +{ +int pos =0 ; + + pos += snprintf(dest+pos, len-pos, "name \"%s\", bus %s",hw/qdev.c DeviceState *qdev_create(BusState *bus, const char *name) · line 122
Quoted 10 lines
hw/qdev.c +10
-0+ info->name, info->bus_info->name); +if (info->alias) + pos +=snprintf (dest+pos, len-pos,", alias \"%s\"" , info->alias); +if (info->desc) + pos +=snprintf (dest+pos, len-pos,", desc \"%s\"" , info->desc); +if (info->no_user) + pos +=snprintf (dest+pos, len-pos,", no-user" ); +return pos; +} +Isn't len-pos vulnerable to underflow here? The formal parameter type is
size_t...[...]
Quoted 8 lines
Quoted 5 lines
Huh? You mean you want be able to pass a buffer larger than 2^31 to that function?
cheers
Gerd
snprintf()returns length of output. This may exceed its buffer size argument.
[ after reading the man page ]
Ah. In case the buffer doesn't fit it doesn't return the number of bytes actually written. It returns the number of bytes needed to print everything.
The logic is wrong then, I'll send a fix.
cheers,
Gerd