Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LwM4t-0006VV-B2 for qemu-devel@nongnu.org; Tue, 21 Apr 2009 15:56:23 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LwM4o-0006UE-S9 for qemu-devel@nongnu.org; Tue, 21 Apr 2009 15:56:20 -0400 Received: from [199.232.76.173] (port=39641 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LwM4o-0006Tn-BW for qemu-devel@nongnu.org; Tue, 21 Apr 2009 15:56:18 -0400 Received: from savannah.gnu.org ([199.232.41.3]:35659 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LwM4n-000223-4k for qemu-devel@nongnu.org; Tue, 21 Apr 2009 15:56:17 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1LwM4m-0007lU-Jo for qemu-devel@nongnu.org; Tue, 21 Apr 2009 19:56:16 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1LwM4m-0007lP-AM for qemu-devel@nongnu.org; Tue, 21 Apr 2009 19:56:16 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Tue, 21 Apr 2009 19:56:16 +0000 Subject: [Qemu-devel] [7197] net: Add parameter checks for VLAN clients (Jan Kiszka) List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 7197 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=7197 Author: aliguori Date: 2009-04-21 19:56:15 +0000 (Tue, 21 Apr 2009) Log Message: ----------- net: Add parameter checks for VLAN clients (Jan Kiszka) This aims at helping the user to find typos or other mistakes in parameter lists passed for VLAN client initialization. The existing parsing infrastructure does not allow a leaner approach, but this is better than nothing IMHO. Signed-off-by: Jan Kiszka Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/net.c Modified: trunk/net.c =================================================================== --- trunk/net.c 2009-04-21 19:56:11 UTC (rev 7196) +++ trunk/net.c 2009-04-21 19:56:15 UTC (rev 7197) @@ -1622,6 +1622,9 @@ int net_client_init(const char *device, const char *p) { + static const char * const fd_params[] = { + "vlan", "name", "fd", NULL + }; char buf[1024]; int vlan_id, ret; VLANState *vlan; @@ -1637,10 +1640,18 @@ name = strdup(buf); } if (!strcmp(device, "nic")) { + static const char * const nic_params[] = { + "vlan", "name", "macaddr", "model", NULL + }; NICInfo *nd; uint8_t *macaddr; int idx = nic_get_free_idx(); + if (check_params(buf, sizeof(buf), nic_params, p) < 0) { + fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", + buf, p); + return -1; + } if (idx == -1 || nb_nics >= MAX_NICS) { fprintf(stderr, "Too Many NICs\n"); ret = -1; @@ -1674,12 +1685,24 @@ ret = idx; } else if (!strcmp(device, "none")) { + if (*p != '\0') { + fprintf(stderr, "qemu: 'none' takes no parameters\n"); + return -1; + } /* does nothing. It is needed to signal that no network cards are wanted */ ret = 0; } else #ifdef CONFIG_SLIRP if (!strcmp(device, "user")) { + static const char * const slirp_params[] = { + "vlan", "name", "hostname", "restrict", "ip", NULL + }; + if (check_params(buf, sizeof(buf), slirp_params, p) < 0) { + fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", + buf, p); + return -1; + } if (get_param_value(buf, sizeof(buf), "hostname", p)) { pstrcpy(slirp_hostname, sizeof(slirp_hostname), buf); } @@ -1721,7 +1744,16 @@ #endif #ifdef _WIN32 if (!strcmp(device, "tap")) { + static const char * const tap_params[] = { + "vlan", "name", "ifname", NULL + }; char ifname[64]; + + if (check_params(buf, sizeof(buf), tap_params, p) < 0) { + fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", + buf, p); + return -1; + } if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) { fprintf(stderr, "tap: no interface name\n"); ret = -1; @@ -1738,11 +1770,24 @@ int fd; vlan->nb_host_devs++; if (get_param_value(buf, sizeof(buf), "fd", p) > 0) { + if (check_params(buf, sizeof(buf), fd_params, p) < 0) { + fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", + buf, p); + return -1; + } fd = strtol(buf, NULL, 0); fcntl(fd, F_SETFL, O_NONBLOCK); net_tap_fd_init(vlan, device, name, fd); ret = 0; } else { + static const char * const tap_params[] = { + "vlan", "name", "ifname", "script", "downscript", NULL + }; + if (check_params(buf, sizeof(buf), tap_params, p) < 0) { + fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", + buf, p); + return -1; + } if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) { ifname[0] = '\0'; } @@ -1759,15 +1804,44 @@ if (!strcmp(device, "socket")) { if (get_param_value(buf, sizeof(buf), "fd", p) > 0) { int fd; + if (check_params(buf, sizeof(buf), fd_params, p) < 0) { + fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", + buf, p); + return -1; + } fd = strtol(buf, NULL, 0); ret = -1; if (net_socket_fd_init(vlan, device, name, fd, 1)) ret = 0; } else if (get_param_value(buf, sizeof(buf), "listen", p) > 0) { + static const char * const listen_params[] = { + "vlan", "name", "listen", NULL + }; + if (check_params(buf, sizeof(buf), listen_params, p) < 0) { + fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", + buf, p); + return -1; + } ret = net_socket_listen_init(vlan, device, name, buf); } else if (get_param_value(buf, sizeof(buf), "connect", p) > 0) { + static const char * const connect_params[] = { + "vlan", "name", "connect", NULL + }; + if (check_params(buf, sizeof(buf), connect_params, p) < 0) { + fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", + buf, p); + return -1; + } ret = net_socket_connect_init(vlan, device, name, buf); } else if (get_param_value(buf, sizeof(buf), "mcast", p) > 0) { + static const char * const mcast_params[] = { + "vlan", "name", "mcast", NULL + }; + if (check_params(buf, sizeof(buf), mcast_params, p) < 0) { + fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", + buf, p); + return -1; + } ret = net_socket_mcast_init(vlan, device, name, buf); } else { fprintf(stderr, "Unknown socket options: %s\n", p); @@ -1778,8 +1852,17 @@ } else #ifdef CONFIG_VDE if (!strcmp(device, "vde")) { + static const char * const vde_params[] = { + "vlan", "name", "sock", "port", "group", "mode", NULL + }; char vde_sock[1024], vde_group[512]; int vde_port, vde_mode; + + if (check_params(buf, sizeof(buf), vde_params, p) < 0) { + fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", + buf, p); + return -1; + } vlan->nb_host_devs++; if (get_param_value(vde_sock, sizeof(vde_sock), "sock", p) <= 0) { vde_sock[0] = '\0';