[Libguestfs] [PATCH supermin] ext2: Create symlinks properly (RHBZ#1470157).

Pino Toscano ptoscano at redhat.com
Thu Jul 13 06:49:31 UTC 2017


On Wednesday, 12 July 2017 18:39:49 CEST Richard W.M. Jones wrote:
> The ext2 filesystem on disk format has two ways to store symlinks.
> For symlinks >= 60 bytes in length, they are stored as files
> (so-called "slow symlinks").  For shorter symlinks the symlink is
> stored in the inode ("fast symlinks").
> 
> Previously we only created slow symlinks even if there are shorter
> than 60 bytes.  This didn't matter until recently, when a change went
> upstream which assumes that symlinks shorter than 60 bytes are always
> stored in the inode, thus breaking the filesystems that we created
> before:
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=1470157#c4
> 
> This changes the code to use the ext2fs_symlink function instead which
> creates fast and slow symlinks properly.
> 
> This fix is required if you use supermin with any Linux kernel >= 4.13.
> 
> The actual fix is two lines replacing ext2_write_file with a simpler
> call to ext2fs_symlink.  The majority of this fix is removing the
> ext2_write_file function which is no longer referenced after that
> change.
> 
> Thanks: Eric Sandeen
> ---

Mostly LGTM, there's one thing to fix.

> @@ -833,7 +792,8 @@ ext2_copy_file (struct ext2_data *data, const char *src, const char *dest)
>      ssize_t r = readlink (src, buf, sizeof buf);
>      if (r == -1)
>        unix_error (errno, (char *) "readlink", caml_copy_string (src));
> -    ext2_write_file (data->fs, ino, buf, r, dest);
> +    buf[r] = '\0';
> +    ext2fs_symlink (data->fs, dir_ino, ino, dest, buf);

Since now we write a trailing zero to 'buf', then the size passed to
the readlink() above must be sizeof(buf)-1, otherwise we truncate the
last character in the rare case the symlink target is long as much as
the buffer passed.  And theoretically a target could be longer than the
arbitrary PATH_MAX, but that's material for a separate change...

-- 
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20170713/15665b5a/attachment.sig>


More information about the Libguestfs mailing list