dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/0192-libmount-Preserve-empty-string-value-in-optstr-parsi.patch

4aa97a
From c0f53628926e9fe8956ea276e30d98817d8cbcd4 Mon Sep 17 00:00:00 2001
4aa97a
From: Filipe Brandenburger <filbranden@google.com>
4aa97a
Date: Wed, 10 Aug 2016 13:27:07 -0700
4aa97a
Subject: [PATCH] libmount: Preserve empty string value in optstr parsing
4aa97a
4aa97a
Recent mount (since the switch to libmount in v2.22) drops the '=' in
4aa97a
mount options that are set to an empty value.  For example, the command
4aa97a
line below will be affected:
4aa97a
4aa97a
  # mount -o rw,myopt='' -t tmpfs tmpfs /mnt/tmp
4aa97a
4aa97a
Fix that by preserving an empty string in the options passed to the
4aa97a
mount(2) syscall when they are present on the command line.
4aa97a
4aa97a
Add test cases to ensure empty string handling is working as expected
4aa97a
and in order to prevent regressions in the future.
4aa97a
4aa97a
Also tested manually by stracing mount commands (on a kernel which
4aa97a
accepts a special extra option, for testing purposes.)
4aa97a
4aa97a
Before this commit:
4aa97a
4aa97a
  # strace -e mount ./mount -t tmpfs -o rw,myopt='' tmpfs /mnt/tmp
4aa97a
  mount("tmpfs", "/mnt/tmp", "tmpfs", MS_MGC_VAL, "myarg") = -1 EINVAL (Invalid argument)
4aa97a
4aa97a
After this commit:
4aa97a
4aa97a
  # strace -e mount ./mount -t tmpfs -o rw,myopt='' tmpfs /mnt/tmp
4aa97a
  mount("tmpfs", "/mnt/tmp", "tmpfs", MS_MGC_VAL, "myopt=") = 0
4aa97a
4aa97a
All test cases pass, including newly added test cases.  Also checked
4aa97a
them with valgrind using:
4aa97a
4aa97a
  $ tests/run.sh --memcheck libmount/optstr
4aa97a
4aa97a
Fixes #332.
4aa97a
4aa97a
Signed-off-by: Filipe Brandenburger <filbranden@google.com>
4aa97a
Signed-off-by: Karel Zak <kzak@redhat.com>
4aa97a
Upstream: http://github.com/karelzak/util-linux/commit/727c689908c5e68c92aa1dd65e0d3bdb6d91c1e5
4aa97a
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1740572
4aa97a
---
4aa97a
 libmount/src/optstr.c                         |  4 +--
4aa97a
 .../libmount/optstr-append-empty-value        |  1 +
4aa97a
 .../libmount/optstr-deduplicate-empty         |  1 +
4aa97a
 .../libmount/optstr-prepend-empty-value       |  1 +
4aa97a
 .../libmount/optstr-remove-empty-value        |  1 +
4aa97a
 tests/expected/libmount/optstr-set-empty      |  1 +
4aa97a
 tests/expected/libmount/optstr-set-new-empty  |  1 +
4aa97a
 .../libmount/optstr-set-new-end-empty         |  1 +
4aa97a
 tests/ts/libmount/optstr                      | 28 +++++++++++++++++++
4aa97a
 9 files changed, 37 insertions(+), 2 deletions(-)
4aa97a
 create mode 100644 tests/expected/libmount/optstr-append-empty-value
4aa97a
 create mode 100644 tests/expected/libmount/optstr-deduplicate-empty
4aa97a
 create mode 100644 tests/expected/libmount/optstr-prepend-empty-value
4aa97a
 create mode 100644 tests/expected/libmount/optstr-remove-empty-value
4aa97a
 create mode 100644 tests/expected/libmount/optstr-set-empty
4aa97a
 create mode 100644 tests/expected/libmount/optstr-set-new-empty
4aa97a
 create mode 100644 tests/expected/libmount/optstr-set-new-end-empty
4aa97a
4aa97a
diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c
4aa97a
index 3c680ff6e..7bd9bbdb5 100644
4aa97a
--- a/libmount/src/optstr.c
4aa97a
+++ b/libmount/src/optstr.c
4aa97a
@@ -186,7 +186,7 @@ static int __mnt_optstr_append_option(char **optstr,
4aa97a
 	sz = osz + nsz + 1;		/* 1: '\0' */
4aa97a
 	if (osz)
4aa97a
 		sz++;			/* ',' options separator */
4aa97a
-	if (vsz)
4aa97a
+	if (value)
4aa97a
 		sz += vsz + 1;		/* 1: '=' */
4aa97a
 
4aa97a
 	p = realloc(*optstr, sz);
4aa97a
@@ -202,7 +202,7 @@ static int __mnt_optstr_append_option(char **optstr,
4aa97a
 	memcpy(p, name, nsz);
4aa97a
 	p += nsz;
4aa97a
 
4aa97a
-	if (vsz) {
4aa97a
+	if (value) {
4aa97a
 		*p++ = '=';
4aa97a
 		memcpy(p, value, vsz);
4aa97a
 		p += vsz;
4aa97a
diff --git a/tests/expected/libmount/optstr-append-empty-value b/tests/expected/libmount/optstr-append-empty-value
4aa97a
new file mode 100644
4aa97a
index 000000000..35adf5c72
4aa97a
--- /dev/null
4aa97a
+++ b/tests/expected/libmount/optstr-append-empty-value
4aa97a
@@ -0,0 +1 @@
4aa97a
+result: >aaa,bbb=BBB,ccc,ddd=<
4aa97a
diff --git a/tests/expected/libmount/optstr-deduplicate-empty b/tests/expected/libmount/optstr-deduplicate-empty
4aa97a
new file mode 100644
4aa97a
index 000000000..63b74f678
4aa97a
--- /dev/null
4aa97a
+++ b/tests/expected/libmount/optstr-deduplicate-empty
4aa97a
@@ -0,0 +1 @@
4aa97a
+result: >bbb,ccc,xxx,ddd,AAA=,fff=eee<
4aa97a
diff --git a/tests/expected/libmount/optstr-prepend-empty-value b/tests/expected/libmount/optstr-prepend-empty-value
4aa97a
new file mode 100644
4aa97a
index 000000000..4cea63527
4aa97a
--- /dev/null
4aa97a
+++ b/tests/expected/libmount/optstr-prepend-empty-value
4aa97a
@@ -0,0 +1 @@
4aa97a
+result: >ddd=,aaa,bbb=BBB,ccc<
4aa97a
diff --git a/tests/expected/libmount/optstr-remove-empty-value b/tests/expected/libmount/optstr-remove-empty-value
4aa97a
new file mode 100644
4aa97a
index 000000000..eee5c95b9
4aa97a
--- /dev/null
4aa97a
+++ b/tests/expected/libmount/optstr-remove-empty-value
4aa97a
@@ -0,0 +1 @@
4aa97a
+result: >aaa,ccc<
4aa97a
diff --git a/tests/expected/libmount/optstr-set-empty b/tests/expected/libmount/optstr-set-empty
4aa97a
new file mode 100644
4aa97a
index 000000000..e0a3300f9
4aa97a
--- /dev/null
4aa97a
+++ b/tests/expected/libmount/optstr-set-empty
4aa97a
@@ -0,0 +1 @@
4aa97a
+result: >aaa,bbb=,ccc<
4aa97a
diff --git a/tests/expected/libmount/optstr-set-new-empty b/tests/expected/libmount/optstr-set-new-empty
4aa97a
new file mode 100644
4aa97a
index 000000000..a1cfb3721
4aa97a
--- /dev/null
4aa97a
+++ b/tests/expected/libmount/optstr-set-new-empty
4aa97a
@@ -0,0 +1 @@
4aa97a
+result: >aaa=,bbb=BBB,ccc<
4aa97a
diff --git a/tests/expected/libmount/optstr-set-new-end-empty b/tests/expected/libmount/optstr-set-new-end-empty
4aa97a
new file mode 100644
4aa97a
index 000000000..d0e9880f3
4aa97a
--- /dev/null
4aa97a
+++ b/tests/expected/libmount/optstr-set-new-end-empty
4aa97a
@@ -0,0 +1 @@
4aa97a
+result: >aaa,bbb=BBB,ccc=<
4aa97a
diff --git a/tests/ts/libmount/optstr b/tests/ts/libmount/optstr
4aa97a
index f6a5c0530..07a548963 100755
4aa97a
--- a/tests/ts/libmount/optstr
4aa97a
+++ b/tests/ts/libmount/optstr
4aa97a
@@ -20,6 +20,10 @@ ts_init_subtest "append-value"
4aa97a
 ts_valgrind $TESTPROG --append "aaa,bbb=BBB,ccc" "ddd" "DDD" &> $TS_OUTPUT
4aa97a
 ts_finalize_subtest
4aa97a
 
4aa97a
+ts_init_subtest "append-empty-value"
4aa97a
+ts_valgrind $TESTPROG --append "aaa,bbb=BBB,ccc" "ddd" "" &> $TS_OUTPUT
4aa97a
+ts_finalize_subtest
4aa97a
+
4aa97a
 ts_init_subtest "prepend"
4aa97a
 ts_valgrind $TESTPROG --prepend "aaa,bbb=BBB,ccc" "ddd" &> $TS_OUTPUT
4aa97a
 ts_finalize_subtest
4aa97a
@@ -28,6 +32,10 @@ ts_init_subtest "prepend-value"
4aa97a
 ts_valgrind $TESTPROG --prepend "aaa,bbb=BBB,ccc" "ddd" "DDD" &> $TS_OUTPUT
4aa97a
 ts_finalize_subtest
4aa97a
 
4aa97a
+ts_init_subtest "prepend-empty-value"
4aa97a
+ts_valgrind $TESTPROG --prepend "aaa,bbb=BBB,ccc" "ddd" "" &> $TS_OUTPUT
4aa97a
+ts_finalize_subtest
4aa97a
+
4aa97a
 ts_init_subtest "set-remove"
4aa97a
 ts_valgrind $TESTPROG --set "aaa,bbb=BBB,ccc" "bbb" &> $TS_OUTPUT
4aa97a
 ts_finalize_subtest
4aa97a
@@ -40,14 +48,26 @@ ts_init_subtest "set-large"
4aa97a
 ts_valgrind $TESTPROG --set "aaa,bbb=BBB,ccc" "bbb" "XXX-YYY-ZZZ" &> $TS_OUTPUT
4aa97a
 ts_finalize_subtest
4aa97a
 
4aa97a
+ts_init_subtest "set-empty"
4aa97a
+ts_valgrind $TESTPROG --set "aaa,bbb=BBB,ccc" "bbb" "" &> $TS_OUTPUT
4aa97a
+ts_finalize_subtest
4aa97a
+
4aa97a
 ts_init_subtest "set-new"
4aa97a
 ts_valgrind $TESTPROG --set "aaa,bbb=BBB,ccc" "aaa" "XXX" &> $TS_OUTPUT
4aa97a
 ts_finalize_subtest
4aa97a
 
4aa97a
+ts_init_subtest "set-new-empty"
4aa97a
+ts_valgrind $TESTPROG --set "aaa,bbb=BBB,ccc" "aaa" "" &> $TS_OUTPUT
4aa97a
+ts_finalize_subtest
4aa97a
+
4aa97a
 ts_init_subtest "set-new-end"
4aa97a
 ts_valgrind $TESTPROG --set "aaa,bbb=BBB,ccc" "ccc" "XXX" &> $TS_OUTPUT
4aa97a
 ts_finalize_subtest
4aa97a
 
4aa97a
+ts_init_subtest "set-new-end-empty"
4aa97a
+ts_valgrind $TESTPROG --set "aaa,bbb=BBB,ccc" "ccc" "" &> $TS_OUTPUT
4aa97a
+ts_finalize_subtest
4aa97a
+
4aa97a
 ts_init_subtest "get"
4aa97a
 ts_valgrind $TESTPROG --get "aaa,bbb=BBB,ccc" "aaa" &> $TS_OUTPUT
4aa97a
 ts_finalize_subtest
4aa97a
@@ -68,6 +88,10 @@ ts_init_subtest "remove-value"
4aa97a
 ts_valgrind $TESTPROG --remove "aaa,bbb=BBB,ccc" "bbb" &> $TS_OUTPUT
4aa97a
 ts_finalize_subtest
4aa97a
 
4aa97a
+ts_init_subtest "remove-empty-value"
4aa97a
+ts_valgrind $TESTPROG --remove "aaa,bbb=,ccc" "bbb" &> $TS_OUTPUT
4aa97a
+ts_finalize_subtest
4aa97a
+
4aa97a
 ts_init_subtest "split"
4aa97a
 ts_valgrind $TESTPROG --split "aaa,bbb=BBB,ccc,x-bar,x-foo=foodata,user=kzak,noexec,nosuid,loop=/dev/loop0" &> $TS_OUTPUT
4aa97a
 ts_finalize_subtest
4aa97a
@@ -92,4 +116,8 @@ ts_init_subtest "deduplicate"
4aa97a
 ts_valgrind $TESTPROG --dedup bbb,ccc,AAA,xxx,AAA=a,AAA=bbb,ddd,AAA=ccc,fff=eee AAA &> $TS_OUTPUT
4aa97a
 ts_finalize_subtest
4aa97a
 
4aa97a
+ts_init_subtest "deduplicate-empty"
4aa97a
+ts_valgrind $TESTPROG --dedup bbb,ccc,AAA,xxx,AAA=a,AAA=bbb,ddd,AAA=,fff=eee AAA &> $TS_OUTPUT
4aa97a
+ts_finalize_subtest
4aa97a
+
4aa97a
 ts_finalize
4aa97a
-- 
4aa97a
2.21.0
4aa97a