From owner-svn-src-head@freebsd.org Mon May 28 13:22:01 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 04FA2EF7394; Mon, 28 May 2018 13:22:01 +0000 (UTC) (envelope-from oshogbo.vx@gmail.com) Received: from mail-wr0-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6FEA56F808; Mon, 28 May 2018 13:22:00 +0000 (UTC) (envelope-from oshogbo.vx@gmail.com) Received: by mail-wr0-x241.google.com with SMTP id y15-v6so20274617wrg.11; Mon, 28 May 2018 06:22:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=FQ+EHn0yJomLcRk+MWSzalsSSBmXcAVewUnZhx2Iof0=; b=X1UDwn1tGEln30I7lzEUTRXNDjo7RLmDsqrhaWn6//M/y94BMn/b0+kxTc/DDwHv6F 4CUz5LAFSTeRpKIdl3Fo2p2ubgmfPSeDg6Fi7jxQLpdnkHcza0QgMqt2YhzjCZ321iqc 5s0VmEXIvgncNuiT+x5Gjl4kPrIdAR3lrlXwv9lxfrfbtVokLp4nI0ewNIN7RKWkwBI7 Ixu+ReuxZ9uzPpKl43+x7UATAfossQZQ664BbrRKktNX4aqjOsYz8lwcDSCNRyCOvG6Q tdzkigUoohbGbAlnCkNFyu70zPOAVDkIUTrTiCzyKPMLOtzA0o0gqRgQBbMd4ULxQPtn PQ5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=FQ+EHn0yJomLcRk+MWSzalsSSBmXcAVewUnZhx2Iof0=; b=Z2ICdmGD66uPcZ25e+mBAGm+wEY66Cau4ZL2rZwCClzL7Qr9LGbolTElpgcC5eYhl0 C1DrebrF5kXdItWKp1RhgZ/jQdpLIEQFu5TS+MZsHrG95xVl787yPqV8kcr6N7euL6PY QyDSHrFLM1m+sUbhbGG+BhElFIQthKmFNGMcTyRodxmZ89AOplBejhVpjo84erzKunVE uO5vDUMlRmar+XTIarEoHuoSBZTxdvw2606zwLE9AZHDudYyUho40umyVYuPk5Ks26tJ QmLaGYrqBCwyRxf0N+yVvPuziLwpwGa+UelYTzG6Bi6DZ7qYnq5DiAR9GmHTPsdhpNIp nc/A== X-Gm-Message-State: ALKqPwfn9c2qgLe+pkOXp/b6DyS1S5rpoT3/rqYndtPX0otSkWxXpV4Q CvlVmBRJgA4Tq6lbOjBd2Rf4990v X-Google-Smtp-Source: ADUXVKIA+3/dvOh/D3XMglzbq6g8nzCzbdfiepdokBWAKxjmtMACWQaAowCZ7Zt43aLG+r5CneUf2Q== X-Received: by 2002:a19:f719:: with SMTP id z25-v6mr6942392lfe.137.1527513718946; Mon, 28 May 2018 06:21:58 -0700 (PDT) Received: from jarvis ([77.79.224.226]) by smtp.gmail.com with ESMTPSA id p17-v6sm5850734ljc.72.2018.05.28.06.21.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 May 2018 06:21:57 -0700 (PDT) Sender: Mariusz Zaborski Date: Mon, 28 May 2018 15:21:06 +0200 From: Mariusz Zaborski To: Marcelo Araujo Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r334275 - head/lib/libc/string Message-ID: <20180528132106.GA55425@jarvis> References: <201805280501.w4S51hbH046599@repo.freebsd.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ZPt4rx8FFjLCG7dd" Content-Disposition: inline In-Reply-To: <201805280501.w4S51hbH046599@repo.freebsd.org> User-Agent: Mutt/1.8.3 (2017-05-23) X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 May 2018 13:22:01 -0000 --ZPt4rx8FFjLCG7dd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello Marcelo, Thanks for working on that :) > =20 > tofree =3D string =3D strdup("abc,def,ghi"); > -assert(string !=3D NULL); > +if (string !=3D NULL) > + while ((token =3D strsep(&string, ",")) !=3D NULL) > + printf("%s\en", token); Please notice: ``` If *stringp is initially NULL, strsep() returns NULL. ``` So I even not sure if you need to check strdup() at this point. > =20 > -while ((token =3D strsep(&string, ",")) !=3D NULL) > - printf("%s\en", token); > - > free(tofree); > +free(string); Here you introduced potential double free. At the end of loop the 'string' will be equals to NULL so there is no point= to free it. If somebody would use this code as example and he from any other r= eason would stop at any other point the string will be pointing to the middle of 'tofree' variable which you already freed. Thanks, --=20 Mariusz Zaborski oshogbo//vx | http://oshogbo.vexillium.org FreeBSD commiter | https://freebsd.org Software developer | http://wheelsystems.com If it's not broken, let's fix it till it is!!1 --ZPt4rx8FFjLCG7dd Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEkD1x0xkJXVVY1Gwf38KEGuLGxWQFAlsMAkEACgkQ38KEGuLG xWSLdQ//cUMf/K0NqR/GMCZd5hkGuguhSLcIkCeF3VtroMlULwxNuhRwKU4oTKRp 76wrKxW9Es6UwQ/aztYKQvGd0MRGdvIvx78oHCMa3yYZP3brCQRjMeMCWH5JdSpT wET29HJec1tqtAssTD8M0FKZap/pD1nHJKiybd9tzBXe8/il/MgwgVfPTNIGvF/d i/GYdKX0HZ+job4FoREqm4yarH5DFGBQBWSq1aQ3r5BvFO6I/NXQQXU6MSIlkzlu IFX52jtX3vVubUw/cbYMgtl+ySa7bdYIb2GBOMfDTlxTA/62tAJJELZDhpW07BZw zZwZS2zQGewA5m4S7KpL2gHLAvOycbMuASbZEl6a1DpD9f3k6yiPjKwhDNeDujYS Xzdi3YQhwrarN8ilF7Sh63MF53j3UNrm6A8pzEeRG6SZIw6PsNdUpc3xzzG88Ys2 jyAxZnatWvqHUbBpMbdY+sqU/qwnxHJ14Jwuqe8zC3XZK88scE77IDku/Faff03x FHp49mTuQoTUD1husvsQhvzhfXW+fSdRG3h2Ic3oQKeh2qARd/orvVtxniW9DKY3 T2zllylsMUcBa8hVUY3cJstjqDTytZJqZTl7sGaERvNKcmWe1Mwi8Yo5nHnYFxEf uiDE0PTPJEdpq/LDOKE0/TG2ScvMa+zBsZJvBecm32xMontqP1Y= =SIPo -----END PGP SIGNATURE----- --ZPt4rx8FFjLCG7dd--