Skip to content

Commit

Permalink
Merge branch 'master' into 655-windows-unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Aug 26, 2015
2 parents 9dd110b + 064e65e commit 4d98b05
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 1 addition & 3 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions psutil/_psutil_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down

0 comments on commit 4d98b05

Please sign in to comment.