cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

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

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