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

Skip to content

Commit 3cb091e

Browse files
committed
Increase buffer for readlink() in case OS will support longer names one day.
1 parent 2f366ca commit 3cb091e

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

Modules/posixmodule.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7087,7 +7087,7 @@ posix_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
70877087
{
70887088
path_t path;
70897089
int dir_fd = DEFAULT_DIR_FD;
7090-
char buffer[MAXPATHLEN];
7090+
char buffer[MAXPATHLEN+1];
70917091
ssize_t length;
70927092
PyObject *return_value = NULL;
70937093
static char *keywords[] = {"path", "dir_fd", NULL};
@@ -7102,16 +7102,17 @@ posix_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
71027102
Py_BEGIN_ALLOW_THREADS
71037103
#ifdef HAVE_READLINKAT
71047104
if (dir_fd != DEFAULT_DIR_FD)
7105-
length = readlinkat(dir_fd, path.narrow, buffer, sizeof(buffer));
7105+
length = readlinkat(dir_fd, path.narrow, buffer, MAXPATHLEN);
71067106
else
71077107
#endif
7108-
length = readlink(path.narrow, buffer, sizeof(buffer));
7108+
length = readlink(path.narrow, buffer, MAXPATHLEN);
71097109
Py_END_ALLOW_THREADS
71107110

71117111
if (length < 0) {
71127112
return_value = path_error(&path);
71137113
goto exit;
71147114
}
7115+
buffer[length] = '\0';
71157116

71167117
if (PyUnicode_Check(path.object))
71177118
return_value = PyUnicode_DecodeFSDefaultAndSize(buffer, length);

0 commit comments

Comments
 (0)