From owner-freebsd-current@FreeBSD.ORG Fri Apr 1 11:40:26 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 2498B106564A; Fri, 1 Apr 2011 11:40:26 +0000 (UTC) (envelope-from pluknet@gmail.com) Received: from mail-qy0-f182.google.com (mail-qy0-f182.google.com [209.85.216.182]) by mx1.freebsd.org (Postfix) with ESMTP id A10608FC14; Fri, 1 Apr 2011 11:40:25 +0000 (UTC) Received: by qyk27 with SMTP id 27so2646442qyk.13 for ; Fri, 01 Apr 2011 04:40:24 -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 :content-transfer-encoding; bh=Zdz/A5tRHX+jUet4WtHoC/QZP17onbK49A7tRfbcXes=; b=hUJKpWoa/qa/S3quSMrOUeuJbQSOsXVE8kSSU0pMcXnK83QyMxRyuqvmkjrF5W7MTu 0Yxlnwnst5jq9R9JrQSH5pQL2fzadrPBmqebplNnQaSuIYshYyFPiiHb2arP+ctpBTfV Vrt5vOa6PQAu1aXz+7qTk/y0E9G8gLileHdlo= 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 :content-transfer-encoding; b=DP5RqZc4JejklIHhhxYCVx5nMBDPq4cQf20UVzhrSTx8EGqwDqeFOn2kBhdvpqPvIK yuoIoBkAWUtD4PD2gu8OKC9d0FakpqpOZ4YI+d8+BSHZzJOFTHLJzeL2MXW6lS6e9TH8 pn+8DRlsdKoTy6IsG9MW+tDFjYuURZE4q+McE= MIME-Version: 1.0 Received: by 10.229.99.80 with SMTP id t16mr3307687qcn.73.1301658024721; Fri, 01 Apr 2011 04:40:24 -0700 (PDT) Sender: pluknet@gmail.com Received: by 10.229.67.68 with HTTP; Fri, 1 Apr 2011 04:40:24 -0700 (PDT) In-Reply-To: References: <20110331210349.GA4112@freebsd.org> Date: Fri, 1 Apr 2011 15:40:24 +0400 X-Google-Sender-Auth: RI45qhEjYXQ7fXIO1-OAnDIMGto Message-ID: From: Sergey Kandaurov To: Alexander Best Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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:40:26 -0000 On 1 April 2011 15:37, Sergey Kandaurov wrote: > 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 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- lib/libdevstat/devstat.c =A0 =A0(revision 220102) > +++ lib/libdevstat/devstat.c =A0 =A0(working copy) > @@ -1014,11 +1014,12 @@ > =A0 =A0 =A0 =A0 * Break the (comma delimited) input string out into separ= ate strings. > =A0 =A0 =A0 =A0 */ > =A0 =A0 =A0 =A0for (tempstr =3D tstr, num_args =A0=3D 0; > - =A0 =A0 =A0 =A0 =A0 =A0(*tempstr =3D strsep(&match_str, ",")) !=3D NULL= && (num_args < 5); > - =A0 =A0 =A0 =A0 =A0 =A0num_args++) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (**tempstr !=3D '\0') > + =A0 =A0 =A0 =A0 =A0 =A0(*tempstr =3D strsep(&match_str, ",")) !=3D NULL= && (num_args < 5); ) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (**tempstr !=3D '\0') { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 num_args++; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (++tempstr >=3D &tstr[5= ]) ^^^^ BTW, this game with pointers might prevent devstat(3) from work on big-endian. > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } > > =A0 =A0 =A0 =A0/* The user gave us too many type arguments */ > =A0 =A0 =A0 =A0if (num_args > 3) { > > Please review, and I will commit the patch. --=20 wbr, pluknet