From 727c689908c5e68c92aa1dd65e0d3bdb6d91c1e5 Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Wed, 10 Aug 2016 13:27:07 -0700 Subject: libmount: Preserve empty string value in optstr parsing Recent mount (since the switch to libmount in v2.22) drops the '=' in mount options that are set to an empty value. For example, the command line below will be affected: # mount -o rw,myopt='' -t tmpfs tmpfs /mnt/tmp Fix that by preserving an empty string in the options passed to the mount(2) syscall when they are present on the command line. Add test cases to ensure empty string handling is working as expected and in order to prevent regressions in the future. Also tested manually by stracing mount commands (on a kernel which accepts a special extra option, for testing purposes.) Before this commit: # strace -e mount ./mount -t tmpfs -o rw,myopt='' tmpfs /mnt/tmp mount("tmpfs", "/mnt/tmp", "tmpfs", MS_MGC_VAL, "myarg") = -1 EINVAL (Invalid argument) After this commit: # strace -e mount ./mount -t tmpfs -o rw,myopt='' tmpfs /mnt/tmp mount("tmpfs", "/mnt/tmp", "tmpfs", MS_MGC_VAL, "myopt=") = 0 All test cases pass, including newly added test cases. Also checked them with valgrind using: $ tests/run.sh --memcheck libmount/optstr Fixes #332. Signed-off-by: Filipe Brandenburger --- libmount/src/optstr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libmount/src/optstr.c') diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c index b342b5f07..9dfab67f3 100644 --- a/libmount/src/optstr.c +++ b/libmount/src/optstr.c @@ -185,7 +185,7 @@ static int __mnt_optstr_append_option(char **optstr, sz = osz + nsz + 1; /* 1: '\0' */ if (osz) sz++; /* ',' options separator */ - if (vsz) + if (value) sz += vsz + 1; /* 1: '=' */ p = realloc(*optstr, sz); @@ -201,7 +201,7 @@ static int __mnt_optstr_append_option(char **optstr, memcpy(p, name, nsz); p += nsz; - if (vsz) { + if (value) { *p++ = '='; memcpy(p, value, vsz); p += vsz; -- cgit v1.2.3-55-g7522