From patchwork Wed Jul 26 10:42:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13327829 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DD270C0015E for ; Wed, 26 Jul 2023 10:42:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.570294.892040 (Exim 4.92) (envelope-from ) id 1qOby3-0003C0-LV; Wed, 26 Jul 2023 10:42:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 570294.892040; Wed, 26 Jul 2023 10:42:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOby3-0003Bt-IV; Wed, 26 Jul 2023 10:42:07 +0000 Received: by outflank-mailman (input) for mailman id 570294; Wed, 26 Jul 2023 10:42:07 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOby3-0003Bn-AH for xen-devel@lists.xenproject.org; Wed, 26 Jul 2023 10:42:07 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0619.outbound.protection.outlook.com [2a01:111:f400:fe02::619]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0ffbf0aa-2ba1-11ee-8613-37d641c3527e; Wed, 26 Jul 2023 12:42:05 +0200 (CEST) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by DB8PR04MB6828.eurprd04.prod.outlook.com (2603:10a6:10:113::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Wed, 26 Jul 2023 10:42:02 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::e5cf:5743:ab60:b14e]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::e5cf:5743:ab60:b14e%5]) with mapi id 15.20.6609.032; Wed, 26 Jul 2023 10:42:01 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0ffbf0aa-2ba1-11ee-8613-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dv+G2PljGTRYju51bE7EcRxPuf//IjsHNgsg8O8BSZTjDo551f+5Ec2aGH8T/rviNRzHDxmiZxs+25vT4KqCCzRO+R8UuoWEmzALqAt8bHMZ45xrHPDQ9Isg3UvteILTLc1daEzjLPURx54pawVYtbLu0Dj8Bmb/V1qjb8M41rHaaboHJlhZF5jlwriJESRrc5xRyVM1XCsMpk8IcgAdzubiDLgVSQRTBpumaagqX6UQgh6lh2MnFW2kNukYFCOZJ13Sqcsl337/OLLE4svyR6kcstMCGBNtwb/vg6CMB98a2946yD+3H+dtVnKiDAnCLVrlZrMGlcEPeHw5rIqyQw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5kslvcGE2F0R7sANvGqX9gghrY4Y889SAtYbuo1YxJQ=; b=DwJMlnQvQu4KGtUPUOV/nkPAY1BEbfmTRs8c5wvGvNLkBW7lIPwu1KqWas2ZbJBTiYKyGgcRZ0qP3SRh/amd/T1vAhOFqaQBo8qUp3NySkNWqHHABeg4l8iRhRZ6CSdM1kFxUVhlYbSoWVF86Ri0bQOrpy6ehlKWR57Jr0VJKkm7TdvyyyVRg4yVdaeJyHT/7R+E2xfic8YGj9klSi1b6nPgeD+SYhqEaurEZ+OSBFdlLMnfsE1YK8b8gIYxkMKpx/MNPvaE3LPpT19uZYY6lX5J1HAvFphiVUL1X5wFpAwfDnKSEwI/dVqhAVJ2cSEH9o9G8s+f4PlTlzhdJzh7YA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5kslvcGE2F0R7sANvGqX9gghrY4Y889SAtYbuo1YxJQ=; b=Z+JO0rwmtN9Y1UkzpQ31BufTHMlSdQ15huFNSpooC9AR5/+ZKRGWPAau6YOWHBnW+HV60hb96Z8QdvKrhbiLY6IyRK3qp86vLecQ2HarBF0s/fyx9akgRV00bV1mPGIOC3uMYIB4vVtE7kBEz/aUCaHbsJ/luAsjy4R2GQuGqQ9PThgw4dkY2PQNCpKaX8Gp385DYD8QqdVJYUq2ivJ7DhNi9voGu2tC49QRqWf7NhABYSfote3hUiKJq9lZtcOJEopSfrUELsntOQ8RKoHfnmqmNL94AxBN83/FqPjIF6zu2Kou6Np7OkgYtnP/QlhWcs0BDkkpK4zMxfrv1SsJ/Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Wed, 26 Jul 2023 12:42:00 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Content-Language: en-US To: "xen-devel@lists.xenproject.org" Cc: Anthony Perard , Wei Liu , Juergen Gross From: Jan Beulich Subject: [PATCH] libxenstat/Linux: pass nul-terminated string to strpbrk() X-ClientProxiedBy: FR2P281CA0160.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:99::9) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|DB8PR04MB6828:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b95216e-b304-4888-1b60-08db8dc4f212 X-LD-Processed: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba,ExtFwd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tNaTQaIfcadOFLMtlQflc67fbR1Zu3gpS3XFthz9Vad2lGXB8BSkm5bqf8OOa92TmDt4jGg8jRLgTu4PFS17kkXqpUrae2rCPZed/JU/JSW9JD3gXuZPugaKD2ZbuiWZs+h8vxnS5Y1FKU7Tpk14KxyGPeeaXQvCR9mPzP4XwxFAIEyhyC58JbBOj1Tmtp+NFyQZYraSMaYJQPfTADLqv1thcL2HwhIM4ku6rTuc6f2MIpN3tZOoU6BpspN4C061qtixMvmCigYlxSqvxYaA/nMsPXOXE+KKyK+02qKBUbV0pfUotfCIpzWhVfVD4DuM/F60l54xK76/BUQS+qaRlE2iw7191iXvML9enX2AlJv/5H46cADQ4I54Bbk4kt3IX/QtLOH/SInQgwOGN3pLHenqcclk4O7GTgPUGSTEtk1Js3X7uQEmAc+/qO2etyu96mOiZPZ1e5Ke82D+t1+YeaKHK13t47dH1tJlQp+jF+k3VLLcZYBw+lE95rPclEOp0s4iMJQSGN58KM3Q0Yg2zB1PnPTW+pLN+GqLru1jJ58tnVyZ0O/xmtYw6Fatx/CYgRe1bJrErfdXGI61pPAQWS7N3pWucMDmP460pL7vhgKOvRy3Unows+5aE6Zf9YFUU8K6aaeGAPb7N2C4LZhKTDQv+aM0amUl4Jqp9jIGmAbQyvcQUteTCni21JiCIK5T X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(376002)(346002)(396003)(366004)(39860400002)(136003)(451199021)(54906003)(478600001)(6486002)(38100700002)(6512007)(41300700001)(5660300002)(8676002)(2616005)(66556008)(6916009)(66476007)(316002)(4326008)(66946007)(8936002)(186003)(107886003)(6506007)(26005)(86362001)(31696002)(2906002)(36756003)(31686004)(66899021)(133343001)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?yHrGuqOpl7s+maBo1TkwQeMO3hzq?= =?utf-8?q?qrQuknvNNL9u/OSaq+s1n94Uje8X96Zny8zliMuIvnk5jJ4Lm0c59QjybO2EfjC7K?= =?utf-8?q?/VqSIYR277ezrmMtFxN1/meFG8s283xfMICTicOM0tpjrGKCIiqSl8AojZiqPPHDg?= =?utf-8?q?RrVHFM0RA1C3w0Bnh9rVijkHJ/FNURQN7Zd1EU8N6GbJkpP+SSQaGr6+J9s80Yp+d?= =?utf-8?q?B7cYywDNJlw3u7ccxQ0h1yrVETJ13wUa1Eit6P+KFBpbpAsPsB7D2WNGMfm4St8l8?= =?utf-8?q?eYDPv3Gj+UNLRZ3A0s5K1veyvT6f/vWm1/8j/msq5mC0EweP2dZwfc1tyveDvxiOc?= =?utf-8?q?7XJmPg01oOK6WwCelCMTwdFUpMEqNF42dP3Xwsj9Qs2zxcVCV+/FXYmL/w758u9w0?= =?utf-8?q?9Yg71k298bedK8Z/GAvXyPvIKf+vDZD0SCKxj1k3IGYIgf07riMb3ttr7sJ5vZQHd?= =?utf-8?q?K3VGgsmDagasDHlnnozU3Qv5CVYO6dl6MeiRSu43RBIDCxL4G80NsiKRyHFym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HeuPRcE?= =?utf-8?q?j2fv4DD17IFzwgEM/5mJLgdJjvpkPdP4AHpvXqiQq99lD74NHYFQUVcy+KL1b1BVc?= =?utf-8?q?S8vaBoWvHyJpyyAItYVWbmSbo7AS2YEHcoaQv9vyLGAhCI6Ik7K3nhwmZTKs6+WWY?= =?utf-8?q?v02WsdVAdjU/?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b95216e-b304-4888-1b60-08db8dc4f212 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jul 2023 10:42:01.8587 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fSTFN+3vbdQh5kSn4b0sX5ZiJ9bEibJQlX6DTC318qhBYG+KqSDQolKntGjHqdKHOb+3XNdBvwZSf0f0rfEbLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR04MB6828 While what "tmp" points to has been cleared at the end of the first iteration of parseNetDevLine()'s main loop, this is too late for the first iteration's invocation of strpbrk() (copying the interface name). Properly nul-terminate the string at population time instead, removing the late clearing. While there also eliminate a confusing (because of being wrong) comment: A regex parsing error would be handled one further scope outwards. Here we're dealing with field 1 vs any of the later fields. Signed-off-by: Jan Beulich Reviewed-by: Juergen Gross Acked-by: Anthony PERARD --- Of course the function leaves much to be desired. We had a report of a problem which may have been because of the issue addressed here. Sadly the reporter hasn't come back with any results, so I have to submit this largely "blindly". --- a/tools/libs/stat/xenstat_linux.c +++ b/tools/libs/stat/xenstat_linux.c @@ -169,6 +169,7 @@ static int parseNetDevLine(char *line, c matches[i].rm_so + 1) * sizeof(char)); for (x = matches[i].rm_so; x < matches[i].rm_eo; x++) tmp[x - matches[i].rm_so] = line[x]; + tmp[x - matches[i].rm_so] = 0; /* We populate all the fields from /proc/net/dev line */ if (i > 1) { @@ -225,15 +226,11 @@ static int parseNetDevLine(char *line, c break; } } - else - /* There were errors when parsing this directly in RE. strpbrk() helps */ - if (iface != NULL) { + else if (iface != NULL) { char *tmp2 = strpbrk(tmp, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); if (tmp2 != NULL) strcpy(iface, tmp2); } - - memset(tmp, 0, matches[i].rm_eo - matches[i].rm_so); } } }