From: Benjamin Tissoires <benjamin.tissoires@gmail.com>
To: Benjamin Tissoires <benjamin.tissoires@gmail.com>,
Jiri Kosina <jkosina@suse.cz>, Jean Delvare <khali@linux-fr.org>,
linux-input@vger.kernel.org, linux-i2c@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 14/14] HID: i2c-hid: fix i2c_hid_get_raw_report count mismatches
Date: Wed, 5 Dec 2012 11:40:02 +0100 [thread overview]
Message-ID: <CAN+gG=Fjyhf-DGcC1=rL_zzjecVCfdmhsV0OWha=uODM94vNXA@mail.gmail.com> (raw)
In-Reply-To: <1354634875-5182-15-git-send-email-benjamin.tissoires@gmail.com>
Hi,
sorry, but when I re-read it, it seems that I missed a +2 in the call
of i2c_hid_get_report.
So Jean, Jiri, please ignore this one. I'm really sorry if you already
started reviewing it.
I'll send a v2 with the missing patches early this afternoon.
Cheers,
Benjamin
On Tue, Dec 4, 2012 at 4:27 PM, Benjamin Tissoires
<benjamin.tissoires@gmail.com> wrote:
> The previous memcpy implementation relied on the size advertized by the
> device. There were no guarantees that buf was big enough.
>
> Some gymnastic is also required with the +2/-2 to take into account
> the first 2 bytes where the total length is supplied by the device.
>
> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
> ---
> drivers/hid/i2c-hid/i2c-hid.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
> index 62988f1..de3566f 100644
> --- a/drivers/hid/i2c-hid/i2c-hid.c
> +++ b/drivers/hid/i2c-hid/i2c-hid.c
> @@ -503,13 +503,14 @@ static int i2c_hid_get_raw_report(struct hid_device *hid,
> {
> struct i2c_client *client = hid->driver_data;
> struct i2c_hid *ihid = i2c_get_clientdata(client);
> + size_t rcount;
> int ret;
>
> if (report_type == HID_OUTPUT_REPORT)
> return -EINVAL;
>
> - if (count > ihid->bufsize)
> - count = ihid->bufsize;
> + if (count > ihid->bufsize - 2)
> + count = ihid->bufsize - 2;
>
> ret = i2c_hid_get_report(client,
> report_type == HID_FEATURE_REPORT ? 0x03 : 0x01,
> @@ -518,7 +519,13 @@ static int i2c_hid_get_raw_report(struct hid_device *hid,
> if (ret < 0)
> return ret;
>
> - count = ihid->inbuf[0] | (ihid->inbuf[1] << 8);
> + rcount = ihid->inbuf[0] | (ihid->inbuf[1] << 8);
> +
> + if (!rcount)
> + return 0;
> +
> + if (count > rcount - 2)
> + count = rcount - 2;
>
> memcpy(buf, ihid->inbuf + 2, count);
>
> --
> 1.8.0.1
>
prev parent reply other threads:[~2012-12-05 10:40 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-04 15:27 [PATCH 00/14] i2c-hid cleanup and bug fixes Benjamin Tissoires
2012-12-04 15:27 ` [PATCH 01/14] HID: i2c-hid: change I2C name Benjamin Tissoires
2012-12-04 16:07 ` Jean Delvare
2012-12-05 9:52 ` Jiri Kosina
2012-12-04 15:27 ` [PATCH 02/14] HID: i2c-hid: fix memory corruption due to missing hid declaration Benjamin Tissoires
2012-12-04 21:42 ` Jean Delvare
2012-12-05 10:10 ` Benjamin Tissoires
2012-12-05 10:13 ` Jiri Kosina
2012-12-04 15:27 ` [PATCH 03/14] HID: i2c-hid: enhance Kconfig Benjamin Tissoires
2012-12-04 21:43 ` Jean Delvare
2012-12-05 9:55 ` Jiri Kosina
2012-12-04 15:27 ` [PATCH 04/14] HID: i2c-hid: fix checkpatch.pl warning Benjamin Tissoires
2012-12-04 21:43 ` Jean Delvare
2012-12-05 9:55 ` Jiri Kosina
2012-12-04 15:27 ` [PATCH 05/14] HID: i2c-hid: fix i2c_hid_dbg macro Benjamin Tissoires
2012-12-04 21:49 ` Jean Delvare
2012-12-05 9:56 ` Jiri Kosina
2012-12-04 15:27 ` [PATCH 06/14] HID: i2c-hid: remove unused static declarations Benjamin Tissoires
2012-12-04 21:51 ` Jean Delvare
2012-12-05 10:03 ` Jiri Kosina
2012-12-04 15:27 ` [PATCH 07/14] HID: i2c-hid: fix return paths Benjamin Tissoires
2012-12-05 9:47 ` Jean Delvare
2012-12-05 10:05 ` Jiri Kosina
2012-12-04 15:27 ` [PATCH 08/14] HID: i2c-hid: fix error messages Benjamin Tissoires
2012-12-05 9:51 ` Jean Delvare
2012-12-05 10:07 ` Jiri Kosina
2012-12-04 15:27 ` [PATCH 09/14] HID: i2c-hid: i2c_hid_get_report may fail Benjamin Tissoires
2012-12-05 9:59 ` Jean Delvare
2012-12-05 10:07 ` Benjamin Tissoires
2012-12-05 10:28 ` Jiri Kosina
2012-12-04 15:27 ` [PATCH 10/14] HID: i2c-hid: reorder allocation/free of buffers Benjamin Tissoires
2012-12-05 10:10 ` Jean Delvare
2012-12-05 10:12 ` Benjamin Tissoires
2012-12-04 15:27 ` [PATCH 11/14] HID: i2c-hid: remove unneeded test in i2c_hid_remove Benjamin Tissoires
2012-12-05 10:13 ` Jean Delvare
2012-12-05 10:30 ` Jiri Kosina
2012-12-04 15:27 ` [PATCH 12/14] HID: i2c-hid: remove extra .irq field in struct i2c_hid Benjamin Tissoires
2012-12-05 10:29 ` Jean Delvare
2012-12-04 15:27 ` [PATCH 13/14] HID: i2c-hid: also call i2c_hid_free_buffers in i2c_hid_remove Benjamin Tissoires
2012-12-05 10:27 ` Jiri Kosina
2012-12-05 10:32 ` Jean Delvare
2012-12-04 15:27 ` [PATCH 14/14] HID: i2c-hid: fix i2c_hid_get_raw_report count mismatches Benjamin Tissoires
2012-12-05 10:40 ` Benjamin Tissoires [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAN+gG=Fjyhf-DGcC1=rL_zzjecVCfdmhsV0OWha=uODM94vNXA@mail.gmail.com' \
--to=benjamin.tissoires@gmail.com \
--cc=jkosina@suse.cz \
--cc=khali@linux-fr.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).