]> git.ipfire.org Git - thirdparty/util-linux.git/commit
libmount: Preserve empty string value in optstr parsing
authorFilipe Brandenburger <filbranden@google.com>
Wed, 10 Aug 2016 20:27:07 +0000 (13:27 -0700)
committerKarel Zak <kzak@redhat.com>
Thu, 11 Aug 2016 08:36:25 +0000 (10:36 +0200)
commitc074a7608428ab55d008da101f6780d421453fd0
tree71fedc75523805f115270940a6ad607f74e7a6d0
parentb2cf95957fc216827234a39de912e4bebb3500a2
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 <filbranden@google.com>
libmount/src/optstr.c
tests/expected/libmount/optstr-append-empty-value [new file with mode: 0644]
tests/expected/libmount/optstr-deduplicate-empty [new file with mode: 0644]
tests/expected/libmount/optstr-prepend-empty-value [new file with mode: 0644]
tests/expected/libmount/optstr-remove-empty-value [new file with mode: 0644]
tests/expected/libmount/optstr-set-empty [new file with mode: 0644]
tests/expected/libmount/optstr-set-new-empty [new file with mode: 0644]
tests/expected/libmount/optstr-set-new-end-empty [new file with mode: 0644]
tests/ts/libmount/optstr