From: Aleksandar Gerasimovski <aleksandar.gerasimovski@hitachi-powergrids.com>
To: "broonie@kernel.org" <broonie@kernel.org>,
"linux-spi@vger.kernel.org" <linux-spi@vger.kernel.org>
Subject: [PATCH] spi: tools: fix input string formatting
Date: Fri, 5 Feb 2021 08:04:10 +0000 [thread overview]
Message-ID: <VI1PR06MB402928E3B0E4C887104BCE22D2B29@VI1PR06MB4029.eurprd06.prod.outlook.com> (raw)
The actual unescape implementation has two bugs:
1. quotation marks from the input string are not removed and are sent
to the spidev, e.g: input string: \"\\xFE\\x01\" will be sent to the
spidev as 0x22 0xfe 0x01 0x22
2. there is not format check for decimal input strings
First bug makes spidev_test unusable when strict spi sequence is needed,
second bug is not nice to have it in.
This patch improves unescape function and fixes above listed bugs.
Signed-off-by: Aleksandar Gerasimovski <aleksandar.gerasimovski@hitachi-powergrids.com>
---
tools/spi/spidev_test.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c
index 83844f8..7c36677 100644
--- a/tools/spi/spidev_test.c
+++ b/tools/spi/spidev_test.c
@@ -89,7 +89,7 @@ static void hex_dump(const void *src, size_t length, size_t line_size,
/*
* Unescape - process hexadecimal escape character
- * converts shell input "\x23" -> 0x23
+ * converts shell input "\\x23" -> 0x23
*/
static int unescape(char *_dst, char *_src, size_t len)
{
@@ -100,6 +100,10 @@ static int unescape(char *_dst, char *_src, size_t len)
unsigned int ch;
while (*src) {
+ if (*src == '"') {
+ src++;
+ continue;
+ }
if (*src == '\\' && *(src+1) == 'x') {
match = sscanf(src + 2, "%2x", &ch);
if (!match)
@@ -108,6 +112,9 @@ static int unescape(char *_dst, char *_src, size_t len)
src += 4;
*dst++ = (unsigned char)ch;
} else {
+ match = sscanf(src, "%2d", &ch);
+ if (!match)
+ pabort("malformed input string");
*dst++ = *src++;
}
ret++;
--
1.8.3.1
next reply other threads:[~2021-02-05 8:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-05 8:04 Aleksandar Gerasimovski [this message]
2021-02-05 16:20 ` [PATCH] spi: tools: fix input string formatting Mark Brown
2021-02-06 10:57 ` Aleksandar Gerasimovski
2021-02-08 10:09 ` Mark Brown
2021-02-08 17:08 ` Aleksandar Gerasimovski
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=VI1PR06MB402928E3B0E4C887104BCE22D2B29@VI1PR06MB4029.eurprd06.prod.outlook.com \
--to=aleksandar.gerasimovski@hitachi-powergrids.com \
--cc=broonie@kernel.org \
--cc=linux-spi@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.