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

Skip to content

Commit 6f3f3e5

Browse files
committed
Increase buffer for readlink() in case OS will support longer names one day.
2 parents 0202c34 + 3cb091e commit 6f3f3e5

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
@@ -6944,7 +6944,7 @@ posix_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
69446944
{
69456945
path_t path;
69466946
int dir_fd = DEFAULT_DIR_FD;
6947-
char buffer[MAXPATHLEN];
6947+
char buffer[MAXPATHLEN+1];
69486948
ssize_t length;
69496949
PyObject *return_value = NULL;
69506950
static char *keywords[] = {"path", "dir_fd", NULL};
@@ -6959,16 +6959,17 @@ posix_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
69596959
Py_BEGIN_ALLOW_THREADS
69606960
#ifdef HAVE_READLINKAT
69616961
if (dir_fd != DEFAULT_DIR_FD)
6962-
length = readlinkat(dir_fd, path.narrow, buffer, sizeof(buffer));
6962+
length = readlinkat(dir_fd, path.narrow, buffer, MAXPATHLEN);
69636963
else
69646964
#endif
6965-
length = readlink(path.narrow, buffer, sizeof(buffer));
6965+
length = readlink(path.narrow, buffer, MAXPATHLEN);
69666966
Py_END_ALLOW_THREADS
69676967

69686968
if (length < 0) {
69696969
return_value = path_error(&path);
69706970
goto exit;
69716971
}
6972+
buffer[length] = '\0';
69726973

69736974
if (PyUnicode_Check(path.object))
69746975
return_value = PyUnicode_DecodeFSDefaultAndSize(buffer, length);

0 commit comments

Comments
 (0)