| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1366,8 +1366,6 @@ WCharArray_get_value(CDataObject *self, void *Py_UNUSED(ignored)) | |||
| 1366 | 1366 | static int | |
| 1367 | 1367 | WCharArray_set_value(CDataObject *self, PyObject *value, void *Py_UNUSED(ignored)) | |
| 1368 | 1368 | { | |
| 1369 | - Py_ssize_t result = 0; | ||
| 1370 | - | ||
| 1371 | 1369 | if (value == NULL) { | |
| 1372 | 1370 | PyErr_SetString(PyExc_TypeError, | |
| 1373 | 1371 | "can't delete attribute"); | |
@@ -1378,29 +1376,24 @@ WCharArray_set_value(CDataObject *self, PyObject *value, void *Py_UNUSED(ignored | |||
| 1378 | 1376 | "unicode string expected instead of %s instance", | |
| 1379 | 1377 | Py_TYPE(value)->tp_name); | |
| 1380 | 1378 | return -1; | |
| 1381 | - } else | ||
| 1382 | - Py_INCREF(value); | ||
| 1379 | + } | ||
| 1383 | 1380 | ||
| 1381 | + Py_ssize_t size = self->b_size / sizeof(wchar_t); | ||
| 1384 | 1382 | Py_ssize_t len = PyUnicode_AsWideChar(value, NULL, 0); | |
| 1385 | 1383 | if (len < 0) { | |
| 1386 | 1384 | return -1; | |
| 1387 | 1385 | } | |
| 1388 | 1386 | // PyUnicode_AsWideChar() returns number of wchars including trailing null byte, | |
| 1389 | 1387 | // when it is called with NULL. | |
| 1390 | - if (((size_t)len-1) > self->b_size/sizeof(wchar_t)) { | ||
| 1388 | + assert(len > 0); | ||
| 1389 | + if (len - 1 > size) { | ||
| 1391 | 1390 | PyErr_SetString(PyExc_ValueError, "string too long"); | |
| 1392 | - result = -1; | ||
| 1393 | - goto done; | ||
| 1394 | - } | ||
| 1395 | - result = PyUnicode_AsWideChar(value, | ||
| 1396 | - (wchar_t *)self->b_ptr, | ||
| 1397 | - self->b_size/sizeof(wchar_t)); | ||
| 1398 | - if (result >= 0 && (size_t)result < self->b_size/sizeof(wchar_t)) | ||
| 1399 | - ((wchar_t *)self->b_ptr)[result] = (wchar_t)0; | ||
| 1400 | - done: | ||
| 1401 | - Py_DECREF(value); | ||
| 1402 | - | ||
| 1403 | - return result >= 0 ? 0 : -1; | ||
| 1391 | + return -1; | ||
| 1392 | + } | ||
| 1393 | + if (PyUnicode_AsWideChar(value, (wchar_t *)self->b_ptr, size) < 0) { | ||
| 1394 | + return -1; | ||
| 1395 | + } | ||
| 1396 | + return 0; | ||
| 1404 | 1397 | } | |
| 1405 | 1398 | ||
| 1406 | 1399 | static PyGetSetDef WCharArray_getsets[] = { | |
@@ -3484,10 +3477,12 @@ _validate_paramflags(PyTypeObject *type, PyObject *paramflags) | |||
| 3484 | 3477 | for (i = 0; i < len; ++i) { | |
| 3485 | 3478 | PyObject *item = PyTuple_GET_ITEM(paramflags, i); | |
| 3486 | 3479 | int flag; | |
| 3487 | - char *name; | ||
| 3480 | + PyObject *name = Py_None; | ||
| 3488 | 3481 | PyObject *defval; | |
| 3489 | 3482 | PyObject *typ; | |
| 3490 | - if (!PyArg_ParseTuple(item, "i|ZO", &flag, &name, &defval)) { | ||
| 3483 | + if (!PyArg_ParseTuple(item, "i|OO", &flag, &name, &defval) || | ||
| 3484 | + !(name == Py_None || PyUnicode_Check(name))) | ||
| 3485 | + { | ||
| 3491 | 3486 | PyErr_SetString(PyExc_TypeError, | |
| 3492 | 3487 | "paramflags must be a sequence of (int [,string [,value]]) tuples"); | |
| 3493 | 3488 | return 0; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1300,7 +1300,6 @@ module. load_flags are as defined for LoadLibraryEx in the\n\ | |||
| 1300 | 1300 | Windows API.\n"; | |
| 1301 | 1301 | static PyObject *load_library(PyObject *self, PyObject *args) | |
| 1302 | 1302 | { | |
| 1303 | - const WCHAR *name; | ||
| 1304 | 1303 | PyObject *nameobj; | |
| 1305 | 1304 | int load_flags = 0; | |
| 1306 | 1305 | HMODULE hMod; | |
@@ -1309,14 +1308,14 @@ static PyObject *load_library(PyObject *self, PyObject *args) | |||
| 1309 | 1308 | if (!PyArg_ParseTuple(args, "U|i:LoadLibrary", &nameobj, &load_flags)) | |
| 1310 | 1309 | return NULL; | |
| 1311 | 1310 | ||
| 1312 | - name = _PyUnicode_AsUnicode(nameobj); | ||
| 1313 | - if (!name) | ||
| 1314 | - return NULL; | ||
| 1315 | - | ||
| 1316 | 1311 | if (PySys_Audit("ctypes.dlopen", "O", nameobj) < 0) { | |
| 1317 | 1312 | return NULL; | |
| 1318 | 1313 | } | |
| 1319 | 1314 | ||
| 1315 | + WCHAR *name = PyUnicode_AsWideCharString(nameobj, NULL); | ||
| 1316 | + if (!name) | ||
| 1317 | + return NULL; | ||
| 1318 | + | ||
| 1320 | 1319 | Py_BEGIN_ALLOW_THREADS | |
| 1321 | 1320 | /* bpo-36085: Limit DLL search directories to avoid pre-loading | |
| 1322 | 1321 | * attacks and enable use of the AddDllDirectory function. | |
@@ -1325,6 +1324,7 @@ static PyObject *load_library(PyObject *self, PyObject *args) | |||
| 1325 | 1324 | err = hMod ? 0 : GetLastError(); | |
| 1326 | 1325 | Py_END_ALLOW_THREADS | |
| 1327 | 1326 | ||
| 1327 | + PyMem_Free(name); | ||
| 1328 | 1328 | if (err == ERROR_MOD_NOT_FOUND) { | |
| 1329 | 1329 | PyErr_Format(PyExc_FileNotFoundError, | |
| 1330 | 1330 | ("Could not find module '%.500S' (or one of its " | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1220,11 +1220,8 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length) | |||
| 1220 | 1220 | "string too long (%zd, maximum length %zd)", | |
| 1221 | 1221 | size, length); | |
| 1222 | 1222 | return NULL; | |
| 1223 | - } else if (size < length-1) | ||
| 1224 | - /* copy terminating NUL character if there is space */ | ||
| 1225 | - size += 1; | ||
| 1226 | - | ||
| 1227 | - if (PyUnicode_AsWideChar(value, (wchar_t *)ptr, size) == -1) { | ||
| 1223 | + } | ||
| 1224 | + if (PyUnicode_AsWideChar(value, (wchar_t *)ptr, length) == -1) { | ||
| 1228 | 1225 | return NULL; | |
| 1229 | 1226 | } | |
| 1230 | 1227 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments