Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 Apr 2011 15:40:24 +0400
From:      Sergey Kandaurov <pluknet@freebsd.org>
To:        Alexander Best <arundel@freebsd.org>
Cc:        freebsd-hackers@freebsd.org, FreeBSD Current <freebsd-current@freebsd.org>
Subject:   Re: issue with devstat_buildmatch(3) and certain strings
Message-ID:  <AANLkTimGGwnAORNPzDYzMD6PoHkri3NdQHht3xyVGytO@mail.gmail.com>
In-Reply-To: <AANLkTinK2u4G9m00RXUKK6C%2BBAtO7SdNNX8Er%2BY4YRNL@mail.gmail.com>
References:  <20110331210349.GA4112@freebsd.org> <AANLkTinK2u4G9m00RXUKK6C%2BBAtO7SdNNX8Er%2BY4YRNL@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 1 April 2011 15:37, Sergey Kandaurov <pluknet@freebsd.org> wrote:
> On 1 April 2011 01:03, Alexander Best <arundel@freebsd.org> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTimGGwnAORNPzDYzMD6PoHkri3NdQHht3xyVGytO>