diff options
author | Christian Heimes <christian@python.org> | 2016-09-23 20:24:45 +0200 |
---|---|---|
committer | Christian Heimes <christian@python.org> | 2016-09-23 20:24:45 +0200 |
commit | fec86273228396b3aaf9e7ab8093b860544842fb (patch) | |
tree | 0dddbf0ffbf7c382762509551737c07cadb639c9 | |
parent | 4e8fa310297fc8c20f1c4f38e7a22219e9c4242a (diff) | |
parent | 6f3f3e5ca47ad00d1c5aaa97dc1a790b94dde3e3 (diff) | |
download | cpython-git-fec86273228396b3aaf9e7ab8093b860544842fb.tar.gz |
Increase buffer for readlink() in case OS will support longer names one day.
-rw-r--r-- | Modules/posixmodule.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 28d30b0f9a..01194aa850 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -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}; @@ -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); |