From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Tokarev Subject: Re: [ANNOUNCE] kvm-83 release Date: Wed, 14 Jan 2009 00:01:04 +0300 Message-ID: <496D0110.2020200@msgid.tls.msk.ru> References: <496C9CE0.2080103@redhat.com> <496CBE09.4060801@wonghome.net> <1231867653.4290.196.camel@localhost.localdomain> <496CFA65.9000706@msgid.tls.msk.ru> <496CFB29.6070809@msgid.tls.msk.ru> <496CFB8E.1060407@codemonkey.ws> Mime-Version: 1.0 Content-Type: text/plain; charset=KOI8-R Content-Transfer-Encoding: 7bit Cc: Mark McLoughlin , John Wong , Avi Kivity , KVM list To: Anthony Liguori Return-path: Received: from hobbit.corpit.ru ([81.13.33.150]:22887 "EHLO hobbit.corpit.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753177AbZAMVBI (ORCPT ); Tue, 13 Jan 2009 16:01:08 -0500 In-Reply-To: <496CFB8E.1060407@codemonkey.ws> Sender: kvm-owner@vger.kernel.org List-ID: Anthony Liguori wrote: >> Michael Tokarev wrote: ... >>>> if (strcmp(vc->model, "tap") == 0 && >>>> - sscanf(vc->info_str, "ifname=%63s ", ifname) == 1 && >>>> + sscanf(vc->info_str, "ifname=%63s,", ifname) == 1 && >> >> And while we're at it.. Why the parsing isn't done like this: >> >> for(tok = strtok(arg, ","); tok; tok = strtok(NULL, ",")) { >> if (strncmp(tok, "ifname=", 7) == 0) >> strcpy(ifname, tok+7); >> else if ... >> } > > Because strtok is extremely evil. I didn't mean strtok, but the way -- something LIKE that, i.e, by splitting the string into args and parsing each in turn. There's getsubopt(3) too, which does exactly that, and which is used by, say, mount(8) to parse mount options (-o foo=bar things). Those home-grown sscanfs tend to become buggy like in this example... And if you dislike strtok especially, there are other alternatives. And speaking of strtok, there's nothing evil in it provided you don't run another strtok sequence while this one is running (it's not reenterant, so to say). Here, let it modify the existing string and replace delimiters with zeros to terminate our tokens, -- nothing wrong with that. It's not worse than silently truncating ifname size to 63 chars first and to IF_NAMESIZE second. If you don't want to modify original string, strdup() or astrdup() are our friends... But that's all details, details, not related to the original issue and question. /mjt