From owner-freebsd-current@FreeBSD.ORG Fri Apr 1 11:37:32 2011 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C0997106564A; Fri, 1 Apr 2011 11:37:32 +0000 (UTC) (envelope-from pluknet@gmail.com) Received: from mail-qy0-f175.google.com (mail-qy0-f175.google.com [209.85.216.175]) by mx1.freebsd.org (Postfix) with ESMTP id 4C6EE8FC14; Fri, 1 Apr 2011 11:37:31 +0000 (UTC) Received: by qyk35 with SMTP id 35so265023qyk.13 for ; Fri, 01 Apr 2011 04:37:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=YFGzsyUW/wDzxon/CIzk4TQC7G/MJJ+dfSm8mbH9g1k=; b=CAgfIB3OtJtnuTR9ehHeqKqYQKxpdk6KrtkXRvFJPrezvkx1RWvZshrP9oirImerF7 /JkvnJgxljLypYXfKKQ3c8W5cDJvGvdgaeyNnw0zCWUIdmj3CMe+XViGNBI/HrukKw3S 7dPpACnK3MAtkl70XZeXW2ilEts9ciRVEgCk4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=qd7aoDG0t5UmU1HkiTYVvfqbg3huf7lSxAM9sYD6b8oBORaH87kZToTYG4z+LqrEyi ZSQne5BLDPaowlpMD9x7mUnAuavPqAySY1XAXaVH2coSxFL8M7bSJvFkx1O9UqnKGkvj pwRQpvGGycJR+9y0n1DsWRtwtvCv+7LWhSPr8= MIME-Version: 1.0 Received: by 10.229.106.34 with SMTP id v34mr3318203qco.111.1301657851444; Fri, 01 Apr 2011 04:37:31 -0700 (PDT) Sender: pluknet@gmail.com Received: by 10.229.67.68 with HTTP; Fri, 1 Apr 2011 04:37:31 -0700 (PDT) In-Reply-To: <20110331210349.GA4112@freebsd.org> References: <20110331210349.GA4112@freebsd.org> Date: Fri, 1 Apr 2011 15:37:31 +0400 X-Google-Sender-Auth: Xr8C6kA7c3PrgaaiBobnJ1Hvago Message-ID: From: Sergey Kandaurov To: Alexander Best Content-Type: text/plain; charset=ISO-8859-1 Cc: freebsd-hackers@freebsd.org, FreeBSD Current Subject: Re: issue with devstat_buildmatch(3) and certain strings X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Apr 2011 11:37:32 -0000 On 1 April 2011 01:03, Alexander Best wrote: > hi there, > > devstat_buildmatch(3) crashes with certain strings. you can test this by > doing one of: > > iostat -t "," > iostat -t ",," > iostat -t "da," > iostat -t ",da," > iostat -t ",da" > iostat -t "da,scsi," > iostat -t ",da,scsi" > iostat -t "da,,scsi" [Someone told me, -hackers isn't appropriate for patches, Cc: -current.] The problem is devstat(3) increments num_args regardless if strsep returned NULL. I think that should work (all your tests pass): Index: lib/libdevstat/devstat.c =================================================================== --- lib/libdevstat/devstat.c (revision 220102) +++ lib/libdevstat/devstat.c (working copy) @@ -1014,11 +1014,12 @@ * Break the (comma delimited) input string out into separate strings. */ for (tempstr = tstr, num_args = 0; - (*tempstr = strsep(&match_str, ",")) != NULL && (num_args < 5); - num_args++) - if (**tempstr != '\0') + (*tempstr = strsep(&match_str, ",")) != NULL && (num_args < 5); ) + if (**tempstr != '\0') { + num_args++; if (++tempstr >= &tstr[5]) break; + } /* The user gave us too many type arguments */ if (num_args > 3) { Please review, and I will commit the patch. -- wbr, pluknet