From 25011b4544e48dffd5978201669f7b9e23da3144 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Fri, 1 Mar 2013 12:08:46 +0000 Subject: [PATCH] fs: Fix improper use of readlink readlink returns a non-NUL terminated buffer. If we are going to terminate its response, we need to make sure that there's space to do so. So the length passed to readlink should be one less than the real length of the buffer. Caught by coverity (#985596) Change-Id: I47081877a54a7b3d99ab8e6ec52d4663acd2eeb6 Reviewed-on: http://gerrit.openafs.org/9328 Tested-by: BuildBot Reviewed-by: Jeffrey Altman --- src/venus/fs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/venus/fs.c b/src/venus/fs.c index d8dc4598c..4ba8ebbde 100644 --- a/src/venus/fs.c +++ b/src/venus/fs.c @@ -1726,8 +1726,8 @@ static int GetLastComponent(const char *data, char **outdir, char **outbase, int *thru_symlink) { - char orig_name[1024]; /*Original name, may be modified */ - char true_name[1024]; /*``True'' dirname (e.g., symlink target) */ + char orig_name[MAXPATHLEN]; /*Original name, may be modified */ + char true_name[MAXPATHLEN]; /*``True'' dirname (e.g., symlink target) */ char *lastSlash; struct stat statbuff; /*Buffer for status info */ int link_chars_read; /*Num chars read in readlink() */ @@ -1758,8 +1758,8 @@ GetLastComponent(const char *data, char **outdir, char **outbase, if (thru_symlink) *thru_symlink = 1; - /* Read name of resolved file */ - link_chars_read = readlink(orig_name, true_name, 1024); + /* Read name of resolved file (leave space for NULL!) */ + link_chars_read = readlink(orig_name, true_name, MAXPATHLEN-1); if (link_chars_read <= 0) { fprintf(stderr, "%s: Can't read target name for '%s' symbolic link!\n", -- 2.39.5