Skip to contentSkip to conversation

net: Fix a potential segfault

PATCH Applied Lin Ma 3 participants 3 messages Jun 11, 2018 – Jun 12, 2018 Networking

lore
Share & tools
lore

Lin Ma

author
#0 lore raw

PATCH v3 1/1 net: Fix a potential segfault

If user forgets to provide any backend types for '-netdev' in qemu CLI, It triggers seg fault.

e.g.

Expected:

$ qemu -netdev id=net0
qemu-system-x86_64: Parameter 'type' is missing

Actual:

$ qemu -netdev id=net0
Segmentation fault (core dumped)
---
 net/net.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/net.c +3 -1
index efb9eaf779..2a3133990c 100644
@@ -1093,7 +1093,9 @@ static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp)
     int ret = -1;
     Visitor *v = opts_visitor_new(opts);
 
-    if (is_netdev && is_help_option(qemu_opt_get(opts, "type"))) {
+    const char *type = qemu_opt_get(opts, "type");
+
+    if (is_netdev && type && is_help_option(type)) {
         show_netdevs();
         exit(0);
     } else {
Signature · 1 line
2.16.2
Reviewed-by on v3 1/1
#1 lore raw
Quoted 24 lines · Lin Ma

If user forgets to provide any backend types for '-netdev' in qemu CLI, It triggers seg fault.

e.g.

Expected:

$ qemu -netdev id=net0
qemu-system-x86_64: Parameter 'type' is missing

Actual:

$ qemu -netdev id=net0
Segmentation fault (core dumped)
---
 net/net.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/net.c +0 -0
index efb9eaf779..2a3133990c 100644

net/net.c static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp) · line 1101

Quoted 10 lines
net/net.c +3 -1
@@ -1093,7 +1093,9 @@ static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp)
     int ret = -1;
     Visitor *v = opts_visitor_new(opts);
 
-    if (is_netdev && is_help_option(qemu_opt_get(opts, "type"))) {
+    const char *type = qemu_opt_get(opts, "type");
+
+    if (is_netdev && type && is_help_option(type)) {
         show_netdevs();
         exit(0);
     } else {
Applied
#2 lore raw
Quoted 27 lines · Thomas Huth
Quoted 26 lines · Lin Ma

If user forgets to provide any backend types for '-netdev' in qemu CLI, It triggers seg fault.

e.g.

Expected:

$ qemu -netdev id=net0
qemu-system-x86_64: Parameter 'type' is missing

Actual:

$ qemu -netdev id=net0
Segmentation fault (core dumped)
---
  net/net.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
net/net.c +0 -0
index efb9eaf779..2a3133990c 100644
@@ -1093,7 +1093,9 @@ static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp)
      int ret = -1;
      Visitor *v = opts_visitor_new(opts);
 
Quoted 9 lines

net/net.c static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp) · line 1101

Quoted 8 lines
net/net.c +3 -1
-    if (is_netdev && is_help_option(qemu_opt_get(opts, "type"))) {
+    const char *type = qemu_opt_get(opts, "type");
+
+    if (is_netdev && type && is_help_option(type)) {
          show_netdevs();
          exit(0);
      } else {

Applied, and queued for -stable.

Thanks