read_fs: fix small memory leaks in read_filesystem()

Fix some memory leaks in read_filesystem()...  Mostly
these are in the error path (where mksquashfs will shortly abort).

There is one (id_table) which is not in the error path, and so
this missing free may have leaked a couple of Kbytes when using
Mksquashfs to append to a filesystem.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
mksquashfs: fix fclose leak in reader_read_file() on I/O error

Reader_read_file() did not close the file if I/O error occurred
when file reading.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
mksquashfs: fix fragment struct leak in write_file_{process|blocks|frag}

Fix small leak in

write_file_process()
write_file_blocks() and
write_file_frag()

if -no-duplicates option is specified on command line.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
actions: fix lexeme to string mapping

The insertion of the '\t' whitespace lexeme in the token_table[]
broke the lexeme value to string mapping...   The mapping relies
on the fact each lexeme value corresponds to the index in
the token_table, i.e. the lexeme value is the same as the
lexeme's index in the token_table.

Move all the whitespace lexemes to the end of the table,
to ensure additional whitespace lexemes can be added in
future without breaking the mapping.  Change the lexeme
values so that they correspond to the new order.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
unsquashfs_xattr: fix memory leak in write_xattr()

Fix memory leak in write_xattr() where the xattr_list was
not freed after use.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
read_xattrs: fix xattr free in get_xattr() in error path

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
Unsquashfs: don't treat unrecognised xattr prefixes as xattr read failure

There are two users for get_xattr(), Mksquashfs uses it to read the
xattrs from the filesystem on appending, and Unsquashfs uses it
to retrieve the xattrs for writing to disk.

Unfortunately, the two users disagree on what to do with unknown
xattr prefixes, Mksquashfs wants to treat this as fatal otherwise
this will cause xattrs to be be lost on appending.  Unsquashfs
on the otherhand should want to retrieve the xattrs which are known and
to ignore the rest, this allows Unsquashfs to cope more gracefully
with future versions which may have unknown xattrs, as long as the
general xattr structure is adhered to, Unsquashfs should be able
to safely ignore unknown xattrs, and to write the ones it knows about,
this is better than completely refusing to retrieve all the xattrs.

So add ignore parameter.  If ignore is TRUE then don't treat unknown
xattr prefixes as a failure to read the xattr.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
unsquashfs: add -user-xattrs option to only extract user.xxx xattrs

Add -user-xattrs option to Unsquashfs to signify that only
user.xxx xattrs are to be extracted.  This suppresses the
error message that is generated if there are non-user xattrs
in the filesystem, and unsquashfs is not being run as root
(and so only user.xxx xattrs can be extracted).

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
unsquashfs: add code to only print "not superuser" error message once

When running as non-superuser if unsquashfs encounters a non
user.xxx xattr, it will print an error message as it cannot
extract these xattrs whilst running as a normal user process.

Unfortunately, for many filesystems, every file can be inadertantly
tagged with a security.xxx xattr, with the direct result trying to
unsquash these results in screenfulls of the same error message!

The previous commit added a -user-xattr option to suppress these error
messages, but this commit goes further, and adds code to
suppress the error message after it printed once, and adds advice
on how to prevent this one error message from being printed in the future!

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
unsquashfs: Improve lsetxattr errror handling

Improve handling of ENOTSUP (not supported), ENOSPC and EDQUOT
(out of space) errors.

In particular, disable xattr output if ENOTSUP is received, and
spupress out of space error message if a lot are generated.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
unsquashfs: check for integer overflow in user input

Check for integer overflow in values derived from processors, which
is input from the user if the -processor option is given.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
mksquashfs: check for integer overflow in user input

Check for integer overflow in values derived from user input.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
pseudo: Improve parse error messages in read_pseudo_def()

Plus add checking for trailing characters

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
xz_wrapper: Add comments describing how compression option functions work

XZ is the only compression algorithm using the "new"
compression option framework.  Add some comments on the
functions that describe how the functions work, and how
they interact with the overall compression options framework.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
action: implement exec() test option

Exec() adds the ability to run a command, with the
result of the test being the exit status of the command;
if the command returns a valid exit status (0), exec() returns
TRUE, otherwise on a bad exit status exec() returns FALSE.

Three environment variables hold:

	- NAME: name of file
	- PATHNAME: pathname of file relative to squashfs root
	- SOURCE_PATHNAME: the pathname of the file in the source
			   directory

Currently only a single argument (without spaces) can be entered
as a command, this is because the actions parser currently lacks the
ability to have arguments with spaces in them (either argument quoted
with '"', or spaces blackslashed with '\')!

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