actions: deal with the unlikely case readlink returns 0 bytes

This should never happen, but, it's easy to adjust the error check
to deal with it, so why not ...

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
actions: readlink doesn't 0 terminate the returned path

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
actions: fix empty action

The empty action leaves orphaned inode entries in the inode_info[] table.
These entries because they are orphaned do not (correctly) get allocated
an inode number.  However, write_inode_lookup_table() does not
deal with these orphaned inode entries with an inode number of 0, and
thus writes outside of the bounds of inode_lookup_table[] causing
memory corruption.

Fix this by adding code to skip any orphaned inode entries - that is
an inode number of 0.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
actions: fix file type test

S_IFSOCK and S_IFLNK are not disjoint from the other file types, i.e.
the S_IFLNK value of 0120000 shares the bits for S_IFREG (0100000) and
S_IFCHR (0020000).

This means a test such as (st_mode & S_IFREG) will also match on
S_IFSOCK and S_IFLNK as they set bit 0100000.

Fix the checks in actions by introducting a helper file_type_match()
which does more nuanced checks.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
actions: add dir_ent to action_data structure

dir_ent is needed for the contained() test operator and for the
new contained_followlink() test operator.

Note: action_data contains some fields which are copied from dir_ent,
and are thus now duplicated.  This will be cleaned up in the near
future.

Historical note: the action_data structure when it was originally
created back in 2012 didn't use the dir_ent structure because at
that time the dir_ent didn't exist when the actions code was called
to evaluate the exclude action().  Iff the exclude action returned
FALSE the dir_ent structure was created then.  Since then dir_scan1()
has been restructured to create the dir_ent structure before any
actions code is called.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
actions: add new contained_followlink() test operator for symbolic links

Test if a symlink appears to be within the source filesystem,
that is, it has a relative path, and the relative path does not
appear to backtrack outside the source filesystem using "..".

This test function evaluates the path for symlinks - that is it
follows any symlinks (and any symlinks that it may contain etc.), to
discover the canonicalised relative path.

This is expensive, if possible consider using the faster
contained() alternative which does not try to follow symlinks

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
actions: contained() should check for nonstandard_pathname

If nonstandard_pathname is set, then we have a symlink entered on the
command line, this by definition is a dangling symlink.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>