From owner-svn-src-all@freebsd.org Fri May 20 04:00:22 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D1A93B43FCD; Fri, 20 May 2016 04:00:22 +0000 (UTC) (envelope-from jason.harmening@gmail.com) Received: from mail-pa0-x244.google.com (mail-pa0-x244.google.com [IPv6:2607:f8b0:400e:c03::244]) (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 AA475121D; Fri, 20 May 2016 04:00:22 +0000 (UTC) (envelope-from jason.harmening@gmail.com) Received: by mail-pa0-x244.google.com with SMTP id xm6so9634678pab.3; Thu, 19 May 2016 21:00:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to; bh=dVie6/xHq4JSKkHUtEKgbFqfAmo0zE5lU/rMOJRW+dA=; b=eay9uX4pZj0kBjagk6+U8K9kq8wKRtiLb+oHYwpuTYGZYB9FMGovhi05C5j9ZuUmbr OpI0vHA1XoHf0VqeOM9I/cpXteaOpQ3nntnaaOaynU8oc/pAEgrGIVTsLczYMbFZptZW K3HIumEbEna+6wCDdDyEEsSSHTZyaPLbVZkXxexBsJe8SGIsAyxwqD4J3DNUmNm3FbCE 82m9s5MewCm3Siw0Vo7pkulwYfhaZDe4wb2TiM/B0+PzJa7DkqWidDjx6NAJrVVpAbbN PjHGFB+WwEKBM4T9KDJPekCjqzLKWN1nE79yzQH6cRoUFVrXjlXetwhMwNcmpQ+akSyX E8Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to; bh=dVie6/xHq4JSKkHUtEKgbFqfAmo0zE5lU/rMOJRW+dA=; b=R3GJtxonQqH2F0yTCfbvAwialKXdMCddU2Wu0xiX4fuwWX6LFaq9TfJ0OfrO1kPGLt 7Pg3GodDO2FBOPBvRVJoREagjfMPvMYVWP2NpKiki94ZS0pjGTMI62b+G9vcpmrQrP0Y UUU/BtR7FqTghNdhRO3VeojIZhAsy36SeykMBr/0wXOF1wHaTqTrXhW6sKiijjRD5bH4 KIFmP17odx9vbkfMzfDmS1DZ+7KNdfgaFpj22Ps5J429y/NT/lHDzDCtfo/Sw9MuPDo3 xhs7sGUZqLe9b79iXyV0A6fAZYae8iKMZ9qnX7XI9zIoK7QBTqD1ZdToonzKWj/wp7pI lgJA== X-Gm-Message-State: AOPr4FVeseLkxyRSsTI6JSf+yCm1l9ojfpvd7rs5PuEBHYV5y66ay82L+EDNPzxS1YTuxg== X-Received: by 10.66.166.6 with SMTP id zc6mr1372788pab.21.1463716822152; Thu, 19 May 2016 21:00:22 -0700 (PDT) Received: from corona.austin.rr.com (c-67-188-30-11.hsd1.ca.comcast.net. [67.188.30.11]) by smtp.googlemail.com with ESMTPSA id br5sm5980761pab.39.2016.05.19.21.00.21 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 19 May 2016 21:00:21 -0700 (PDT) Subject: Re: svn commit: r300258 - head/sys/dev/iicbus To: Ravi Pokala , "Jason A. Harmening" , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org References: <201605200303.u4K334pG019632@repo.freebsd.org> <371B94E2-E906-4F9C-9A9B-A9D35CD93D21@panasas.com> From: Jason Harmening Message-ID: <573E8CFB.8090007@gmail.com> Date: Thu, 19 May 2016 21:05:15 -0700 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <371B94E2-E906-4F9C-9A9B-A9D35CD93D21@panasas.com> Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="wdfkXCrMBbsV3tTt1XrLIdUCnou6BPrgo" X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 May 2016 04:00:22 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --wdfkXCrMBbsV3tTt1XrLIdUCnou6BPrgo Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 05/19/16 20:50, Ravi Pokala wrote: > -----Original Message----- > From: on behalf of "Jason A. Harmeni= ng" > Date: 2016-05-19, Thursday at 20:03 > To: , , > Subject: svn commit: r300258 - head/sys/dev/iicbus >=20 >> Author: jah >> Date: Fri May 20 03:03:04 2016 >> New Revision: 300258 >> URL: https://svnweb.freebsd.org/changeset/base/300258 >> >> Log: >> iic_rdwr_data->nmsgs is uint32_t, so limit the allowable number of me= ssages to prevent memory exhaustion and short allocations on 32-bit syste= ms. Since iicrdwr is intended to be a workalike of a Linux i2c-dev call, = use the same limit of 42 that Linux uses. >> =20 >> Also check the return value of copyin(9) to prevent unnecessary alloc= ation in the failure case. >> =20 >> ... >> =20 >> error =3D copyin(d->msgs, buf, sizeof(*d->msgs) * d->nmsgs); >> + if (error !=3D 0) { >> + free(buf, M_IIC); >> + return (error); >> + } >> >=20 > Hi Jason, >=20 > If I=E2=80=99m reading that right, it=E2=80=99s not preventing any allo= cations, but it is preventing a leak. Is that correct? >=20 > Thanks, >=20 > Ravi (rpokala@) >=20 >=20 Hi Ravi, There shouldn't be a leak in here, but checking the result prevents falling through the rest of the function, including the unnecessary malloc of usrbufs right after this. It also makes the error handling clearer. Thanks, Jason --wdfkXCrMBbsV3tTt1XrLIdUCnou6BPrgo Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQF8BAEBCgBmBQJXPoz8XxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXRENkY3MTQyREU0MTU4MTgyRkZDNUU2ODVC QjlGOEJGOTkyODQxRDFCAAoJELufi/mShB0b47oIAI/bEO3FBfBJzir97Td4AZ2W veG1JMN+yLlnUX0FG8Ij+VOzqu2+vRhONPgp68zEIMyaPwLQS5eyTfWmowibRJbX FM+DrulKhI/mNUZ9r2QluilB7PIrJtXwcpGZbVeu84dOfYWgDDbqfIwSlF8kyxLh YDvkFeu86vZabocP9ovzt8Kjw1epJ0jcpVm/uK3BI6gsYvV7iQ7jJQDOXZCvYhlu QbCkppO42SfzexgCLcyD+uXrVFiXddaCQp9g3E0OeSf408to4gBdwstpnN/EQMYT Q4GWvd3P23RpBeAHOGxEIq1h5admLd+F7+c0/LYm0s0bxvtL6beqexFnmZuMKhE= =xVDU -----END PGP SIGNATURE----- --wdfkXCrMBbsV3tTt1XrLIdUCnou6BPrgo--