Received: from eggs.gnu.org ([208.118.235.92]:54391) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USewU-0003tq-MH for qemu-devel@nongnu.org; Wed, 17 Apr 2013 22:51:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1USewR-0002eM-Cb for qemu-devel@nongnu.org; Wed, 17 Apr 2013 22:51:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47546) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USewR-0002eE-0d for qemu-devel@nongnu.org; Wed, 17 Apr 2013 22:51:19 -0400 Date: Thu, 18 Apr 2013 10:51:14 +0800 From: Amos Kong Message-ID: <20130418025114.GA3684@t430s.nay.redhat.com> References: <1365693118-6603-1-git-send-email-akong@redhat.com> <20130416081150.GC6308@stefanha-thinkpad.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130416081150.GC6308@stefanha-thinkpad.redhat.com> Subject: Re: [Qemu-devel] [RFC PATCH] net: introduce monitor command to query mactables List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org, laine@redhat.com, mst@redhat.com Hi Stefan, On Tue, Apr 16, 2013 at 10:11:50AM +0200, Stefan Hajnoczi wrote: > On Thu, Apr 11, 2013 at 11:11:58PM +0800, Amos Kong wrote: > > +static MacTableInfo *virtio_net_query_mactable(NetClientState *nc) > > +{ .... > > + for (i = 0; i < n->mac_table.first_multi; i++) { > > + info->has_unicast = true; > > + entry = g_malloc0(sizeof(*entry)); > > + sprintf(str, > > + "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", > > + n->mac_table.macs[i * ETH_ALEN], > > + n->mac_table.macs[i * ETH_ALEN + 1], > > + n->mac_table.macs[i * ETH_ALEN + 2], > > + n->mac_table.macs[i * ETH_ALEN + 3], > > + n->mac_table.macs[i * ETH_ALEN + 4], > > + n->mac_table.macs[i * ETH_ALEN + 5]); > > Buffer overflow, char str[12], but luckily... > > > + entry->value = g_malloc0(sizeof(String *)); > > + entry->value->str = g_strdup(str); > > ...these lines can be replaced with g_strdup_printf(): > https://developer.gnome.org/glib/2.28/glib-String-Utility-Functions.html#g-strdup-printf Fixed, thanks. > > diff --git a/net/net.c b/net/net.c > > index 7869161..2103e7f 100644 > > --- a/net/net.c > > +++ b/net/net.c > > @@ -964,6 +964,29 @@ void print_net_client(Monitor *mon, NetClientState *nc) > > nc->info_str); .... > Please add an optional net client name argument so the user can query > just a single NIC. This saves users from having to parse out a specific > NIC when they just want to query one. The reason why I didn't add argument is: All current info/query commands don't have arguments, Is there a special reason? (info network, info qtree, etc) output info of all devices. But we have interface to support this (.args_type), I will add the useful argument for info/query mac-table. -- Amos.