summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2015-08-26 03:03:01 -0700
committerGiampaolo Rodola <g.rodola@gmail.com>2015-08-26 03:03:01 -0700
commit064e65ede4c6fe0cc35887c4593de99d0243b7b0 (patch)
tree51fe34accf91816d3542522ce56af9c5a370cd2c
parent58211221f70071531585665fcfa8ba4f21645d5f (diff)
downloadpsutil-064e65ede4c6fe0cc35887c4593de99d0243b7b0.tar.gz
#655: fix net_if_stats unicode error
-rw-r--r--HISTORY.rst4
-rw-r--r--psutil/_psutil_windows.c12
2 files changed, 10 insertions, 6 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index def4bb3e..1d175594 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -12,11 +12,9 @@ Bug tracker at https://github.com/giampaolo/psutil/issues
- #513: [Linux] fixed integer overflow for RLIM_INFINITY.
- #641: [Windows] fixed many compilation warnings. (patch by Jeff Tang)
+- #655: [Windows] net_if_stats unicode error in in case of non-ASCII NIC names.
- #659: [Linux] compilation error on Suse 10.
- #664: [Linux] compilation error on Alpine Linux. (patch by Bart van Kleef)
-
-**Bug fixes**
-
- #670: [Windows] segfgault of net_if_addrs() in case of non-ASCII NIC names.
(patch by sk6249)
- #672: [Windows] compilation fails if using Windows SDK v8.0. (patch by
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index 504f8ccc..07345f0f 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -3004,10 +3004,10 @@ psutil_net_if_stats(PyObject *self, PyObject *args) {
MIB_IFROW *pIfRow;
PIP_ADAPTER_ADDRESSES pAddresses = NULL;
PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL;
- char friendly_name[MAX_PATH];
char descr[MAX_PATH];
int ifname_found;
+ PyObject *py_nic_name = NULL;
PyObject *py_retdict = PyDict_New();
PyObject *py_ifc_info = NULL;
PyObject *py_is_up = NULL;
@@ -3052,7 +3052,11 @@ psutil_net_if_stats(PyObject *self, PyObject *args) {
while (pCurrAddresses) {
sprintf_s(descr, MAX_PATH, "%wS", pCurrAddresses->Description);
if (lstrcmp(descr, pIfRow->bDescr) == 0) {
- sprintf_s(friendly_name, MAX_PATH, "%wS", pCurrAddresses->FriendlyName);
+ py_nic_name = PyUnicode_FromWideChar(
+ pCurrAddresses->FriendlyName,
+ wcslen(pCurrAddresses->FriendlyName));
+ if (py_nic_name == NULL)
+ goto error;
ifname_found = 1;
break;
}
@@ -3085,8 +3089,9 @@ psutil_net_if_stats(PyObject *self, PyObject *args) {
);
if (!py_ifc_info)
goto error;
- if (PyDict_SetItemString(py_retdict, friendly_name, py_ifc_info))
+ if (PyDict_SetItemString(py_retdict, py_nic_name, py_ifc_info))
goto error;
+ Py_DECREF(py_nic_name);
Py_DECREF(py_ifc_info);
}
@@ -3097,6 +3102,7 @@ psutil_net_if_stats(PyObject *self, PyObject *args) {
error:
Py_XDECREF(py_is_up);
Py_XDECREF(py_ifc_info);
+ Py_XDECREF(py_nic_name);
Py_DECREF(py_retdict);
if (pIfTable != NULL)
free(pIfTable);