Skip to content

Commit

Permalink
bootloader: Fix uninitialized variable on AIX.
Browse files Browse the repository at this point in the history
Yet instead of just initializing this variable with ``0`` in the else-branch,
better use ``snprintf()``, as Thomas Waldmann suggested, which sets ``len`` to
the actual number of characters copied.

Co-authored-by: Thomas Waldmann <tw@waldmann-edv.de>
Co-authored-by: Hartmut Goebel <h.goebel@crazy-compilers.com>
  • Loading branch information
3 people committed May 2, 2020
1 parent ce7658c commit afe197d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
19 changes: 10 additions & 9 deletions bootloader/src/pyi_pythonlib.c
Expand Up @@ -14,6 +14,8 @@
/*
* Functions to load, initialize and launch Python.
*/
/* size of buffer to store the name of the Python DLL library */
#define DLLNAME_LEN (64)

/* TODO: use safe string functions */
#define _CRT_SECURE_NO_WARNINGS 1
Expand Down Expand Up @@ -55,9 +57,9 @@ pyi_pylib_load(ARCHIVE_STATUS *status)
{
dylib_t dll;
char dllpath[PATH_MAX];
char dllname[64];
char dllname[DLLNAME_LEN];
char *p;
int len;
size_t len;

/*
* On AIX Append the name of shared object library path might be an archive.
Expand All @@ -82,21 +84,20 @@ pyi_pylib_load(ARCHIVE_STATUS *status)
pyvers_major = pyvers / 10;
pyvers_minor = pyvers % 10;

len = snprintf(dllname, 64,
len = snprintf(dllname, DLLNAME_LEN,
"libpython%01d.%01d.a(libpython%01d.%01d.so)",
pyvers_major, pyvers_minor, pyvers_major, pyvers_minor);
}
else {
strncpy(dllname, status->cookie.pylibname, 64);
len = snprintf(dllname, DLLNAME_LEN, "%s", status->cookie.pylibname);
}
#else
len = 0;
strncpy(dllname, status->cookie.pylibname, 64);
len = snprintf(dllname, DLLNAME_LEN, "%s", status->cookie.pylibname);
#endif

if (len >= 64 || dllname[64-1] != '\0') {
FATALERROR("Reported length (%d) of DLL name (%s) length exceeds buffer[64] space\n",
len, status->cookie.pylibname);
if (len >= DLLNAME_LEN) {
FATALERROR("Reported length (%d) of DLL name (%s) length exceeds buffer[%d] space\n",
len, status->cookie.pylibname, DLLNAME_LEN);
return -1;
}

Expand Down
1 change: 1 addition & 0 deletions news/4728.bugfix.rst
@@ -0,0 +1 @@
* (AIX) Fix uninitialized variable.
1 change: 1 addition & 0 deletions news/4734.bugfix.rst
@@ -0,0 +1 @@
* (AIX) Fix uninitialized variable.

0 comments on commit afe197d

Please sign in to comment.