[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] libxenstat/Linux: pass nul-terminated string to strpbrk()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 26 Jul 2023 12:42:00 +0200
  • 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
  • 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-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==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Anthony Perard <anthony.perard@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Juergen Gross <jgross@xxxxxxxx>
  • Delivery-date: Wed, 26 Jul 2023 10:42:14 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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 <jbeulich@xxxxxxxx>
---
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);
                        }
                }
        }



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.