Increase buffer for readlink() in case OS will support longer names one day.

This commit is contained in:
Christian Heimes 2016-09-23 20:24:45 +02:00
commit fec8627322
1 changed files with 4 additions and 3 deletions

View File

@ -6944,7 +6944,7 @@ posix_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
{ {
path_t path; path_t path;
int dir_fd = DEFAULT_DIR_FD; int dir_fd = DEFAULT_DIR_FD;
char buffer[MAXPATHLEN]; char buffer[MAXPATHLEN+1];
ssize_t length; ssize_t length;
PyObject *return_value = NULL; PyObject *return_value = NULL;
static char *keywords[] = {"path", "dir_fd", NULL}; static char *keywords[] = {"path", "dir_fd", NULL};
@ -6959,16 +6959,17 @@ posix_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_READLINKAT #ifdef HAVE_READLINKAT
if (dir_fd != DEFAULT_DIR_FD) if (dir_fd != DEFAULT_DIR_FD)
length = readlinkat(dir_fd, path.narrow, buffer, sizeof(buffer)); length = readlinkat(dir_fd, path.narrow, buffer, MAXPATHLEN);
else else
#endif #endif
length = readlink(path.narrow, buffer, sizeof(buffer)); length = readlink(path.narrow, buffer, MAXPATHLEN);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
if (length < 0) { if (length < 0) {
return_value = path_error(&path); return_value = path_error(&path);
goto exit; goto exit;
} }
buffer[length] = '\0';
if (PyUnicode_Check(path.object)) if (PyUnicode_Check(path.object))
return_value = PyUnicode_DecodeFSDefaultAndSize(buffer, length); return_value = PyUnicode_DecodeFSDefaultAndSize(buffer, length);