Whamcloud - gitweb
util: avoid off-by-one on long symlinks
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 20 Jul 2015 14:42:40 +0000 (10:42 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 22 Jul 2015 04:17:07 +0000 (00:17 -0400)
readlink does not nul terminate its result, therefore one extra byte
has to be taken into account.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
util/symlinks.c

index abb33f8..3acebe7 100644 (file)
@@ -166,7 +166,7 @@ static void fix_symlink (char *path, dev_t my_dev)
        struct stat stbuf, lstbuf;
        int c, fix_abs = 0, fix_messy = 0, fix_long = 0;
 
-       if ((c = readlink(path, lpath, sizeof(lpath))) == -1) {
+       if ((c = readlink(path, lpath, sizeof(lpath) - 1)) == -1) {
                perror(path);
                return;
        }