]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
fs: Fix improper use of readlink
authorSimon Wilkinson <sxw@your-file-system.com>
Fri, 1 Mar 2013 12:08:46 +0000 (12:08 +0000)
committerJeffrey Altman <jaltman@your-file-system.com>
Sun, 10 Mar 2013 03:12:47 +0000 (19:12 -0800)
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 <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
src/venus/fs.c

index d8dc4598cc1326569b1ffb2a90209104fdb7f65a..4ba8ebbdefe77fce0b80604d1c9379d1d31ab68e 100644 (file)
@@ -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",