]> git.karo-electronics.de Git - linux-beck.git/commitdiff
spi: spidev_test: check error
authorJoshua Clayton <stillcompiling@gmail.com>
Wed, 18 Nov 2015 22:30:41 +0000 (14:30 -0800)
committerMark Brown <broonie@kernel.org>
Mon, 23 Nov 2015 14:54:01 +0000 (14:54 +0000)
Check the result of sscanf to verify a result was found.
report and error and abort if pattern was not found.

Signed-off-by: Joshua Clayton <stillcompiling@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
tools/spi/spidev_test.c

index 02fc3a44901b5b625d636906acd3385727a007c0..322370dbc7702f333d2fb1e2e87af08add5a5228 100644 (file)
@@ -86,13 +86,17 @@ static void hex_dump(const void *src, size_t length, size_t line_size, char *pre
 static int unescape(char *_dst, char *_src, size_t len)
 {
        int ret = 0;
+       int match;
        char *src = _src;
        char *dst = _dst;
        unsigned int ch;
 
        while (*src) {
                if (*src == '\\' && *(src+1) == 'x') {
-                       sscanf(src + 2, "%2x", &ch);
+                       match = sscanf(src + 2, "%2x", &ch);
+                       if (!match)
+                               pabort("malformed input string");
+
                        src += 4;
                        *dst++ = (unsigned char)ch;
                } else {