net: Reject non-netdevs in qmp_netdev_del()
The netdev_del command crashes when given a -net device, because it
calls qemu_opts_del(NULL).
Check that this is a -netdev before attempting to delete it and the
QemuOpts.
Note the subtle change from qemu_find_opts_err("netdev", errp) to
qemu_find_opts_err("netdev", NULL).  Since "netdev" is a built in
options group and we don't check for NULL return anyway, there's no use
in passing errp here.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
			
			
This commit is contained in:
		
							parent
							
								
									f0e3ac7034
								
							
						
					
					
						commit
						645c9496f7
					
				
							
								
								
									
										9
									
								
								net.c
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								net.c
									
									
									
									
									
								
							@ -827,6 +827,7 @@ exit_err:
 | 
				
			|||||||
void qmp_netdev_del(const char *id, Error **errp)
 | 
					void qmp_netdev_del(const char *id, Error **errp)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    NetClientState *nc;
 | 
					    NetClientState *nc;
 | 
				
			||||||
 | 
					    QemuOpts *opts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    nc = qemu_find_netdev(id);
 | 
					    nc = qemu_find_netdev(id);
 | 
				
			||||||
    if (!nc) {
 | 
					    if (!nc) {
 | 
				
			||||||
@ -834,8 +835,14 @@ void qmp_netdev_del(const char *id, Error **errp)
 | 
				
			|||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    opts = qemu_opts_find(qemu_find_opts_err("netdev", NULL), id);
 | 
				
			||||||
 | 
					    if (!opts) {
 | 
				
			||||||
 | 
					        error_setg(errp, "Device '%s' is not a netdev", id);
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    qemu_del_net_client(nc);
 | 
					    qemu_del_net_client(nc);
 | 
				
			||||||
    qemu_opts_del(qemu_opts_find(qemu_find_opts_err("netdev", errp), id));
 | 
					    qemu_opts_del(opts);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void print_net_client(Monitor *mon, NetClientState *nc)
 | 
					void print_net_client(Monitor *mon, NetClientState *nc)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user