From patchwork Fri Feb 5 08:04:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aleksandar Gerasimovski X-Patchwork-Id: 377884 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F79CC433E0 for ; Fri, 5 Feb 2021 08:05:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 02FC464F97 for ; Fri, 5 Feb 2021 08:05:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230221AbhBEIFB (ORCPT ); Fri, 5 Feb 2021 03:05:01 -0500 Received: from mail-eopbgr150112.outbound.protection.outlook.com ([40.107.15.112]:49879 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230209AbhBEIE7 (ORCPT ); Fri, 5 Feb 2021 03:04:59 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h+9nM8P74OX6u/LE40JTeb6makBGu+8DVojmutXH8XmYf17dZbLqmhVjctn1tNQKREhWnTxklFSllDt7F4U2DXkmEmTxiy97bKSkNxslNEWs0JD6pUV9GiWSzYTWr9a449bRHy7D7NGlv1FE4SSl6LdjPFZIG1C8RpXx9EQODZMivT2kT1Eq4WUK7NeHjeEtJbVv1G7efghX2lQV9ab3Pjx3hcPBtnlBZ1Sar5v/GR5L09pWPPjMBexmw2UDuLxoEBwQC17XPQZXU9tBxTlVVUE4vAJBjGbw/p2LK6ZAI1OMT+1YyijHF2F6U8E6iVtWS5BEzxo5Mrl59OYlJgXhow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kCi7xYO/1TIErzzIAiYBLfzHcnGeDgtF7uBSacsq5YI=; b=Udyq57mCrGel1SbX8lqsLUsjWVQKVY+kEEoHaWIHtr7+qrI3fOB+b39y/f8PqydOswez3mJb0KgcnudWX/yVUAgupePV9XRc9kH36iEnJr6exJ00YEuOTf9WNNGhpWnUp24z/9F0rMyY64/pDJeYG5mrkgx8Ut6niSaSdur6dvsHfp1THF2dG7MM2OfWf5MNPIw1BTyeln9hnScEbqfX2bx0YnkXVdvW58yZHpPTJ8mAR+0iwP6hKEsDk85W9R8JuwMvW3MQPuxoOJQFn/vl26Il6QtzuLg6Ut+za1EslUnA5xITK3Xb4JJofKVzuyGe3h969tWv5uuRQU3l17iNcQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hitachi-powergrids.com; dmarc=pass action=none header.from=hitachi-powergrids.com; dkim=pass header.d=hitachi-powergrids.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hitachi-powergrids.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kCi7xYO/1TIErzzIAiYBLfzHcnGeDgtF7uBSacsq5YI=; b=OyZK/dUV9YNy7K95uG+ax5zoS+bjhldnJG+eAePH8BYafH9w8BUi9IHD6GFqZznbRCHpZ7/Yqb8nxMjtTvgS9jHuJOwwzrT1jwGY6NqXuAhUc4M961Zc1Dy9M9H00AmbQ7csLuELl+tXviSJMfc5Cem6XYH/LRCgOmXzYqCmE+o= Received: from VI1PR06MB4029.eurprd06.prod.outlook.com (2603:10a6:802:5d::10) by VI1PR0602MB3247.eurprd06.prod.outlook.com (2603:10a6:802:c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.23; Fri, 5 Feb 2021 08:04:11 +0000 Received: from VI1PR06MB4029.eurprd06.prod.outlook.com ([fe80::5122:a590:b5fb:658e]) by VI1PR06MB4029.eurprd06.prod.outlook.com ([fe80::5122:a590:b5fb:658e%4]) with mapi id 15.20.3805.025; Fri, 5 Feb 2021 08:04:11 +0000 From: Aleksandar Gerasimovski To: "broonie@kernel.org" , "linux-spi@vger.kernel.org" Subject: [PATCH] spi: tools: fix input string formatting Thread-Topic: [PATCH] spi: tools: fix input string formatting Thread-Index: Adb7lWXMIZfEJF6fRI2btRVdFMCGkg== Date: Fri, 5 Feb 2021 08:04:10 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-processedbytemplafy: true authentication-results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=hitachi-powergrids.com; x-originating-ip: [80.75.192.110] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 21378f92-cd38-4f63-d5e1-08d8c9ac9ee0 x-ms-traffictypediagnostic: VI1PR0602MB3247: x-microsoft-antispam-prvs: x-abb-o365-outbound: ABBOUTBOUND1 x-ms-oob-tlc-oobclassifiers: OLM:8273; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: XMHQPmXTy/kkRoD+kmGXwu3aTXk2+efNk96lTRMWOxiAnuZq15FRVy+KJEtPqQ2BMJ8+CFhhFhOuGCX40YD8cTLmM9HnPfbZngoiDYtvXsixR4ie5Rm017wF55xQ14E2i5TjK4SRLFjBF2vm3/NKiWsytMy6nJDpAVWI3RDm0DAZQkl+/oz6RfXnmQ1I8ptgCcGROh9eRdpgu8Dj+Nq/d8NhNRGJOlDuXgc5GsiGbJwvv+tte9uqf6tkxPsCbIFnP0zRXjx/LO3diJJFITRbewE8aFavJTtcUibjK5QF/yFqYtd2QYnLliQgcuS47bmQTlwclEOQmcmIEnLoMuLEQSTpOrboV5h4NFV3vPjlOXMsJLg+hJkxn85rXFlIyd02C6vw1Sxa6QeiFadvzMZ6uuLxaVPGvQ+TZ31xQFSUDqMKqurlRJRAdF4zPoJxJKIuO9tYswDwbEWhMgeFW+4biw5oFb/v1wb6wz9+KtKZVUw7wTRUZ8pjQXShoaxdL4PSt4BTDCfAueMkVUFS5ujYXg== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR06MB4029.eurprd06.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(39860400002)(366004)(346002)(136003)(396003)(52536014)(5660300002)(2906002)(64756008)(66556008)(66476007)(66446008)(44832011)(7696005)(26005)(66946007)(76116006)(71200400001)(8676002)(86362001)(8936002)(6506007)(33656002)(478600001)(110136005)(9686003)(55016002)(186003)(83380400001)(316002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: =?iso-8859-1?q?Pr3eLxApX90TfrS+TKFbuC?= =?iso-8859-1?q?XbHvbsG8fbHjIT0IDoXAMiz5O8sfwGyByLbImu5uGJGB7iBSBrX?= =?iso-8859-1?q?negye/dY2O+Yl8nQX6QyTu7nRkPLpV9ZuHsCzwbaTQUjfm82xxn?= =?iso-8859-1?q?BCPMhAWeeiNZKJ7E3StK3bS9vcDypsXScyY6mLBsUJzCuRnahiW?= =?iso-8859-1?q?sW3yTAmuCJlmDGo4Oju0VWW+WLU3YTFRsumBCZWlbWxqkxWK4SS?= =?iso-8859-1?q?oDNdLOsemm3aSE8cEHRg0P1Pa95I6wTU1xjsQgKvUUFva2KZ4QN?= =?iso-8859-1?q?C6WHglBfI54pza2apxi0MJ/oU+g7hcPZDfmgxNIxcB6YO55Uc9c?= =?iso-8859-1?q?EujMNRqIgbU6czlrlxhxjNQafqhUfX0zEwly9AvPG721p4B8gYu?= =?iso-8859-1?q?kw7KcszKWG3tp1AYQXjeZPpoLki4DuTUyfFQfZWAtRnbILwe/l5?= =?iso-8859-1?q?G381oPlCJ6TvDAygJXei5F6IGpLS4e/SApq1+EzNgHctws443xW?= =?iso-8859-1?q?9mgqiAxiR6a5tjM7ANsxjIiA5ronzHChevdUwG2Yea8nnYgHwi1?= =?iso-8859-1?q?TWGIuYzY/ExZgTfDMgSpK/uVR3ZU+JvU5f2l3k19Hpei5eg4Mcc?= =?iso-8859-1?q?TyRg/rMxc5qJWdZRFrut7AJCgBB/8d9NyV+JmAX66nb752ay1ye?= =?iso-8859-1?q?YS6ZYS6swZ/8AdOkxqsU0fBhT/5M3Vrrj5Css+0SrpOzHSj4rtM?= =?iso-8859-1?q?5iuhIoexz1+qrMkU4aOW29jIHiUbrkFANUY0eVaW2mPv7Scu58D?= =?iso-8859-1?q?BW2YYUJTgi3AsfQzZ2wi7RRoXdqLUQAHA30OERKq1YBj5LBh+jc?= =?iso-8859-1?q?gcks2wH9PhBJatDF07rgHEYjwZI7+SLvQ7Q6+NKjtxu0u+uHEPm?= =?iso-8859-1?q?JLYjzVMQGuqakMdUyvxMTJMzhbPz2W3s+Gk3g5h+o2bbW9R2diF?= =?iso-8859-1?q?1E9034jisJoxv6Kd/5sALKUPBpT8tQgJuLbkMM70Iydz4kaAvdc?= =?iso-8859-1?q?T3McBSZBpkTvjGC9esViyrAnN2UnoOs6yb9/rVqk9sJPMFhgll1?= =?iso-8859-1?q?dnrruzYtkpIhkc8bdIAeJBl/K1wtTuP7l8kGcTnEhwcyZ7PnYuU?= =?iso-8859-1?q?LWObzMZRrAQwN8abhdwlMcpve++mQznrWdUlWi4d+VDbQBX/8Io?= =?iso-8859-1?q?gmKtBPUyk8jZNolu4D7DCeAz73Ox5TbXhQh+92BEFcdUaWhYlMT?= =?iso-8859-1?q?hIFZL5yRsABJuhZShTj7mwULt47coWGt9oyZhtFrsx2ZM3CubJg?= =?iso-8859-1?q?3LhU59ZrXjojR66c2NZ8XOR2i0xPaCReofbClqRMhidZRZMzt5v?= =?iso-8859-1?q?r7WAIU/tVZqwPaH0LO5UUSuQynVkxxV11auSkpcvMR+IzOYInPW?= =?iso-8859-1?q?m6fpBu8s2VQqGTfrBczykUhPeponpie6RxbE157hdSzYzOv?= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: hitachi-powergrids.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR06MB4029.eurprd06.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21378f92-cd38-4f63-d5e1-08d8c9ac9ee0 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Feb 2021 08:04:10.9598 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 7831e6d9-dc6c-4cd1-9ec6-1dc2b4133195 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: QjX46fBTzOdiqaQIiyGwgEtTnltJ6XvyzWuQ53LlpociDgZGHoKtketCN+U1RWkCX1T4E73mCW4LQoqnWl8N6Si1tOl4fAOR0VsSRtuvxTFX6Jqy7Fa7ye1ZRECJZp4Bs1skLeO5n4UbSO78lnEZkQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0602MB3247 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org 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 --- 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++;