linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Fuzzey <mfuzzey@parkeon.com>
To: Henrik Rydberg <rydberg@euromail.se>,
	Nick Dyer <nick.dyer@itdev.co.uk>,
	linux-input@vger.kernel.org
Subject: [PATCH] Input: atmel_mxt_ts: Fix random configuration load failure
Date: Mon, 09 Feb 2015 19:31:47 +0100	[thread overview]
Message-ID: <20150209183147.26132.22331.stgit@localhost> (raw)

Sometimes configuration fails to load with:

	Bad format: failed to parse object

This can occur because the firmware loader does not ensure that
the configuration data is null terminated.

The scanf() therefore reads arbitrary garbage at the end of file.
If one item of garbage happens to be parsable the error occurs.

By skipping control characters (line endings) before scanning
each line rather than relying on the white space skipping of sscanf
we correctly detect end of file.

Signed-off-by: Martin Fuzzey <mfuzzey@parkeon.com>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 0666759..29f9b9d 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -1086,6 +1086,13 @@ static int mxt_prepare_cfg_mem(struct mxt_data *data,
 	u8 val;
 
 	while (data_pos < cfg->size) {
+		if (cfg->data[data_pos] < 0x20) {
+			/* firmware loading does not ensure null termination
+			 * which is required by scanf */
+			 data_pos++;
+			 continue;
+		}
+
 		/* Read type, instance, length */
 		ret = sscanf(cfg->data + data_pos, "%x %x %x%n",
 			     &type, &instance, &size, &offset);


                 reply	other threads:[~2015-02-09 19:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20150209183147.26132.22331.stgit@localhost \
    --to=mfuzzey@parkeon.com \
    --cc=linux-input@vger.kernel.org \
    --cc=nick.dyer@itdev.co.uk \
    --cc=rydberg@euromail.se \
    /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).