Skip to contentSkip to conversation

tools/xenstat: handle network interface name in uppercase.

PATCH In review Zhigang Wang 2 participants 6 messages Mar 11, 2016 – Apr 20, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/xenstat: handle network interface name in uppercase.

xentop will segmentation fault in this case:

  # ip link set eth1 down
  # ip link set eth1 name ETH
  # xentop

This patch will let xentop to handle all uppercase network interface name.

---
 tools/xenstat/libxenstat/src/xenstat_linux.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/xenstat/libxenstat/src/xenstat_linux.c +6 -2
index 931b24e..d33eca1 100644
@@ -101,6 +101,7 @@ int parseNetDevLine(char *line, char *iface, unsigned long long *rxBytes, unsign
 	/* Temporary/helper variables */
 	int ret;
 	char *tmp;
+	char *tmp2;
 	int i = 0, x = 0, col = 0;
 	regex_t r;
 	regmatch_t matches[19];
@@ -221,8 +222,11 @@ int parseNetDevLine(char *line, char *iface, unsigned long long *rxBytes, unsign
 				}
 				else
 				/* There were errors when parsing this directly in RE. strpbrk() helps */
-				if (iface != NULL)
-					strcpy(iface, strpbrk(tmp, "abcdefghijklmnopqrstvuwxyz0123456789"));
+				if (iface != NULL) {
+					tmp2 = strpbrk(tmp, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
+					if (tmp2 != NULL)
+						strcpy(iface, tmp2);
+				}
 
 				memset(tmp, 0, matches[i].rm_eo - matches[i].rm_so);
 			}
Signature · 7 lines
2.5.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#1 lore raw

Could anyone have a look at this patch?

Thanks,

Zhigang

Quoted 30 lines · Zhigang Wang

xentop will segmentation fault in this case:

  # ip link set eth1 down
  # ip link set eth1 name ETH
  # xentop

This patch will let xentop to handle all uppercase network interface name.

---
 tools/xenstat/libxenstat/src/xenstat_linux.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/xenstat/libxenstat/src/xenstat_linux.c +1 -0
index 931b24e..d33eca1 100644
@@ -101,6 +101,7 @@ int parseNetDevLine(char *line, char *iface, unsigned long long *rxBytes, unsign
 	/* Temporary/helper variables */
 	int ret;
 	char *tmp;
+	char *tmp2;
 	int i = 0, x = 0, col = 0;
 	regex_t r;
 	regmatch_t matches[19];
@@ -221,8 +222,11 @@ int parseNetDevLine(char *line, char *iface, unsigned long long *rxBytes, unsign
 				}
 				else
 				/* There were errors when parsing this directly in RE. strpbrk() helps */

tools/xenstat/libxenstat/src/xenstat_linux.c int parseNetDevLine(char *line, char *iface, unsigned long long *rxBytes, unsign · line 232

Quoted 10 lines
tools/xenstat/libxenstat/src/xenstat_linux.c +5 -2
-				if (iface != NULL)
-					strcpy(iface, strpbrk(tmp, "abcdefghijklmnopqrstvuwxyz0123456789"));
+				if (iface != NULL) {
+					tmp2 = strpbrk(tmp, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
+					if (tmp2 != NULL)
+						strcpy(iface, tmp2);
+				}
 
 				memset(tmp, 0, matches[i].rm_eo - matches[i].rm_so);
 			}

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
In reply to Zhigang Wang

I wasn't CC'ed so this fled my attention.

Quoted 26 lines · Zhigang Wang

xentop will segmentation fault in this case:

  # ip link set eth1 down
  # ip link set eth1 name ETH
  # xentop

This patch will let xentop to handle all uppercase network interface name.

---
 tools/xenstat/libxenstat/src/xenstat_linux.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/xenstat/libxenstat/src/xenstat_linux.c +1 -0
index 931b24e..d33eca1 100644
@@ -101,6 +101,7 @@ int parseNetDevLine(char *line, char *iface, unsigned long long *rxBytes, unsign
 	/* Temporary/helper variables */
 	int ret;
 	char *tmp;
+	char *tmp2;
 	int i = 0, x = 0, col = 0;
 	regex_t r;
 	regmatch_t matches[19];

tools/xenstat/libxenstat/src/xenstat_linux.c int parseNetDevLine(char *line, char *iface, unsigned long long *rxBytes, unsign · line 224

Quoted 3 lines
tools/xenstat/libxenstat/src/xenstat_linux.c +0 -0
@@ -221,8 +222,11 @@ int parseNetDevLine(char *line, char *iface, unsigned long long *rxBytes, unsign
 				}
 				else
 				/* There were errors when parsing this directly in RE. strpbrk() helps */

This line indicates the most proper fix is to fix the regexp used to also parse netdev name IMHO. That being said, there is no reason to block a valid fix.

tools/xenstat/libxenstat/src/xenstat_linux.c int parseNetDevLine(char *line, char *iface, unsigned long long *rxBytes, unsign · line 229

Quoted 7 lines
tools/xenstat/libxenstat/src/xenstat_linux.c +5 -2
-				if (iface != NULL)
-					strcpy(iface, strpbrk(tmp, "abcdefghijklmnopqrstvuwxyz0123456789"));
+				if (iface != NULL) {
+					tmp2 = strpbrk(tmp, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
+					if (tmp2 != NULL)
+						strcpy(iface, tmp2);
+				}

Please limit the scope of tmp2, if you only need that here, declare it within this narrow scope please.

Wei.

Quoted 11 lines
tools/xenstat/libxenstat/src/xenstat_linux.c +0 -0
 				memset(tmp, 0, matches[i].rm_eo - matches[i].rm_so);
 			}
Signature · 7 lines
2.5.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw

PATCH 1/1 tools/xenstat: handle network interface name in uppercase.

xentop will segmentation fault in this case:

  # ip link set eth1 down
  # ip link set eth1 name ETH
  # xentop

This patch will let xentop to handle all uppercase network interface name.

---
 tools/xenstat/libxenstat/src/xenstat_linux.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/xenstat/libxenstat/src/xenstat_linux.c +5 -2
index 2cc9c7f..907d65f 100644
@@ -219,8 +219,11 @@ int parseNetDevLine(char *line, char *iface, unsigned long long *rxBytes, unsign
 				}
 				else
 				/* There were errors when parsing this directly in RE. strpbrk() helps */
-				if (iface != NULL)
-					strcpy(iface, strpbrk(tmp, "abcdefghijklmnopqrstvuwxyz0123456789"));
+				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);
 			}
Signature · 7 lines
2.5.5


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on v1 1/1
#4 lore raw
Quoted 9 lines · Zhigang Wang

xentop will segmentation fault in this case:

  # ip link set eth1 down
  # ip link set eth1 name ETH
  # xentop

This patch will let xentop to handle all uppercase network interface name.

This fixes a real problem and is not possible to block the pushgate, so:

Quoted 25 lines
---
 tools/xenstat/libxenstat/src/xenstat_linux.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/xenstat/libxenstat/src/xenstat_linux.c +5 -2
index 2cc9c7f..907d65f 100644
@@ -219,8 +219,11 @@ int parseNetDevLine(char *line, char *iface, unsigned long long *rxBytes, unsign
 				}
 				else
 				/* There were errors when parsing this directly in RE. strpbrk() helps */
-				if (iface != NULL)
-					strcpy(iface, strpbrk(tmp, "abcdefghijklmnopqrstvuwxyz0123456789"));
+				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);
 			}
Signature · 1 line
2.5.5

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Applied
#5 lore raw
Quoted 9 lines · Wei Liu
Quoted 8 lines · Zhigang Wang

xentop will segmentation fault in this case:

  # ip link set eth1 down
  # ip link set eth1 name ETH
  # xentop

This patch will let xentop to handle all uppercase network interface name.

Quoted 8 lines
Quoted 1 line

This fixes a real problem and is not possible to block the pushgate, so:

Applied.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel