diff --git a/bootloader/src/pyi_pythonlib.c b/bootloader/src/pyi_pythonlib.c index 2c45895c963..356c8b27da9 100644 --- a/bootloader/src/pyi_pythonlib.c +++ b/bootloader/src/pyi_pythonlib.c @@ -392,10 +392,11 @@ pyi_pylib_start_python(ARCHIVE_STATUS *status) * its contents nor free its memory. * * NOTE: Statics are zero-initialized. */ - static char pypath[3 * PATH_MAX + 32]; + #define MAX_PYPATH_SIZE (3 * PATH_MAX + 32) + static char pypath[MAX_PYPATH_SIZE]; /* Wide string forms of the above, for Python 3. */ - static wchar_t pypath_w[PATH_MAX + 1]; + static wchar_t pypath_w[MAX_PYPATH_SIZE]; static wchar_t pyhome_w[PATH_MAX + 1]; static wchar_t progname_w[PATH_MAX + 1]; @@ -420,26 +421,26 @@ pyi_pylib_start_python(ARCHIVE_STATUS *status) /* Set sys.path */ /* sys.path = [mainpath/base_library.zip, mainpath/lib-dynload, mainpath] */ - if (snprintf(pypath, sizeof pypath, "%s%c%s" "%c" "%s%c%s" "%c" "%s", + if (snprintf(pypath, MAX_PYPATH_SIZE, "%s%c%s" "%c" "%s%c%s" "%c" "%s", status->mainpath, PYI_SEP, "base_library.zip", PYI_PATHSEP, status->mainpath, PYI_SEP, "lib-dynload", PYI_PATHSEP, status->mainpath) - >= sizeof pypath) { + >= MAX_PYPATH_SIZE) { // This should never happen, since mainpath is < PATH_MAX and pypath is // huge enough FATALERROR("sys.path (based on %s) exceeds buffer[%d] space\n", - status->mainpath, sizeof pypath); + status->mainpath, MAX_PYPATH_SIZE); return -1; } /* - * E must set sys.path to have base_library.zip before + * We must set sys.path to have base_library.zip before * calling Py_Initialize as it needs `encodings` and other modules. */ /* Decode using current locale */ - if (!pyi_locale_char2wchar(pypath_w, pypath, PATH_MAX)) { + if (!pyi_locale_char2wchar(pypath_w, pypath, MAX_PYPATH_SIZE)) { FATALERROR("Failed to convert pypath to wchar_t\n"); return -1; }