usbobserver: use surrogateescape for undecodable file names

This commit is contained in:
Kovid Goyal 2023-01-23 16:27:19 +05:30
parent 5f4437f7fa
commit d17c1c6ce8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -283,7 +283,11 @@ usbobserver_get_mounted_filesystems(PyObject *self, PyObject *args) {
for (i = 0 ; i < num; i++) {
val = PyUnicode_FromString(buf[i].f_mntonname);
if (!val) {
PyErr_Clear();
val = PyUnicode_DecodeLocale(buf[i].f_mntonname, "surrogateescape");
if (!val) { NUKE(ans); goto end; }
}
if (PyDict_SetItemString(ans, buf[i].f_mntfromname, val) != 0) { NUKE(ans); NUKE(val); goto end; }
NUKE(val);
}