Skip to content

Commit

Permalink
Increase buffer for readlink() in case OS will support longer names o…
Browse files Browse the repository at this point in the history
…ne day.
  • Loading branch information
tiran committed Sep 23, 2016
2 parents 4e8fa31 + 6f3f3e5 commit fec8627
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -6944,7 +6944,7 @@ posix_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
{
path_t path;
int dir_fd = DEFAULT_DIR_FD;
char buffer[MAXPATHLEN];
char buffer[MAXPATHLEN+1];
ssize_t length;
PyObject *return_value = NULL;
static char *keywords[] = {"path", "dir_fd", NULL};
Expand All @@ -6959,16 +6959,17 @@ posix_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_READLINKAT
if (dir_fd != DEFAULT_DIR_FD)
length = readlinkat(dir_fd, path.narrow, buffer, sizeof(buffer));
length = readlinkat(dir_fd, path.narrow, buffer, MAXPATHLEN);
else
#endif
length = readlink(path.narrow, buffer, sizeof(buffer));
length = readlink(path.narrow, buffer, MAXPATHLEN);
Py_END_ALLOW_THREADS

if (length < 0) {
return_value = path_error(&path);
goto exit;
}
buffer[length] = '\0';

if (PyUnicode_Check(path.object))
return_value = PyUnicode_DecodeFSDefaultAndSize(buffer, length);
Expand Down

0 comments on commit fec8627

Please sign in to comment.