Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 269aeb7

Browse files
author
Victor Stinner
committed
zipimport: pass path size to make_filename()
Don't hardcode path size in make_filename().
1 parent f040d7d commit 269aeb7

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

Modules/zipimport.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ get_subname(char *fullname)
216216
archive (without extension) to the path buffer. Return the
217217
length of the resulting string. */
218218
static int
219-
make_filename(PyObject *prefix_obj, char *name, char *path)
219+
make_filename(PyObject *prefix_obj, char *name, char *path, size_t pathsize)
220220
{
221221
size_t len;
222222
char *p;
@@ -228,7 +228,7 @@ make_filename(PyObject *prefix_obj, char *name, char *path)
228228
len = PyBytes_GET_SIZE(prefix);
229229

230230
/* self.prefix + name [+ SEP + "__init__"] + ".py[co]" */
231-
if (len + strlen(name) + 13 >= MAXPATHLEN) {
231+
if (len + strlen(name) + 13 >= pathsize - 1) {
232232
PyErr_SetString(ZipImportError, "path too long");
233233
Py_DECREF(prefix);
234234
return -1;
@@ -263,7 +263,7 @@ get_module_info(ZipImporter *self, char *fullname)
263263

264264
subname = get_subname(fullname);
265265

266-
len = make_filename(self->prefix, subname, path);
266+
len = make_filename(self->prefix, subname, path, sizeof(path));
267267
if (len < 0)
268268
return MI_ERROR;
269269

@@ -507,7 +507,7 @@ zipimporter_get_source(PyObject *obj, PyObject *args)
507507
}
508508
subname = get_subname(fullname);
509509

510-
len = make_filename(self->prefix, subname, path);
510+
len = make_filename(self->prefix, subname, path, sizeof(path));
511511
if (len < 0)
512512
return NULL;
513513

@@ -1171,7 +1171,7 @@ get_module_code(ZipImporter *self, char *fullname,
11711171

11721172
subname = get_subname(fullname);
11731173

1174-
len = make_filename(self->prefix, subname, path);
1174+
len = make_filename(self->prefix, subname, path, sizeof(path));
11751175
if (len < 0)
11761176
return NULL;
11771177

0 commit comments

Comments
 (0)