Merge pull request #17154 from keszybz/crypttab-commas
Allow escaping commas in crypttab
This commit is contained in:
@@ -13,12 +13,11 @@ int fstab_filter_options(const char *opts, const char *names,
|
||||
*/
|
||||
|
||||
static void do_fstab_filter_options(const char *opts,
|
||||
const char *remove,
|
||||
int r_expected,
|
||||
const char *name_expected,
|
||||
const char *value_expected,
|
||||
const char *filtered_expected) {
|
||||
|
||||
const char *remove,
|
||||
int r_expected,
|
||||
const char *name_expected,
|
||||
const char *value_expected,
|
||||
const char *filtered_expected) {
|
||||
int r;
|
||||
const char *name;
|
||||
_cleanup_free_ char *value = NULL, *filtered = NULL;
|
||||
@@ -34,7 +33,7 @@ static void do_fstab_filter_options(const char *opts,
|
||||
|
||||
/* also test the malloc-less mode */
|
||||
r = fstab_filter_options(opts, remove, &name, NULL, NULL);
|
||||
log_info("\"%s\" → %d, \"%s\", expected %d, \"%s\"",
|
||||
log_info("\"%s\" → %d, \"%s\", expected %d, \"%s\"\n-",
|
||||
opts, r, name,
|
||||
r_expected, name_expected);
|
||||
assert_se(r == r_expected);
|
||||
@@ -54,6 +53,12 @@ static void test_fstab_filter_options(void) {
|
||||
do_fstab_filter_options("opt,other", "x-opt\0opt\0", 1, "opt", NULL, "other");
|
||||
do_fstab_filter_options("x-opt,other", "opt\0x-opt\0", 1, "x-opt", NULL, "other");
|
||||
|
||||
do_fstab_filter_options("opt=0\\,1,other", "opt\0x-opt\0", 1, "opt", "0,1", "other");
|
||||
do_fstab_filter_options("opt=0,other,x-opt\\,foobar", "x-opt\0opt\0", 1, "opt", "0", "other,x-opt\\,foobar");
|
||||
do_fstab_filter_options("opt,other,x-opt\\,part", "opt\0x-opt\0", 1, "opt", NULL, "other,x-opt\\,part");
|
||||
do_fstab_filter_options("opt,other,part\\,x-opt", "x-opt\0opt\0", 1, "opt", NULL, "other,part\\,x-opt");
|
||||
do_fstab_filter_options("opt,other\\,\\,\\,opt,x-part", "opt\0x-opt\0", 1, "opt", NULL, "other\\,\\,\\,opt,x-part");
|
||||
|
||||
do_fstab_filter_options("opto=0,other", "opt\0x-opt\0", 0, NULL, NULL, NULL);
|
||||
do_fstab_filter_options("opto,other", "opt\0x-opt\0", 0, NULL, NULL, NULL);
|
||||
do_fstab_filter_options("x-opto,other", "opt\0x-opt\0", 0, NULL, NULL, NULL);
|
||||
|
||||
+40
-27
@@ -162,71 +162,84 @@ static void test_strv_find_startswith(void) {
|
||||
}
|
||||
|
||||
static void test_strv_join(void) {
|
||||
_cleanup_free_ char *p = NULL, *q = NULL, *r = NULL, *s = NULL, *t = NULL, *v = NULL, *w = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
p = strv_join((char **)input_table_multiple, ", ");
|
||||
_cleanup_free_ char *p = strv_join((char **)input_table_multiple, ", ");
|
||||
assert_se(p);
|
||||
assert_se(streq(p, "one, two, three"));
|
||||
|
||||
q = strv_join((char **)input_table_multiple, ";");
|
||||
_cleanup_free_ char *q = strv_join((char **)input_table_multiple, ";");
|
||||
assert_se(q);
|
||||
assert_se(streq(q, "one;two;three"));
|
||||
|
||||
r = strv_join((char **)input_table_multiple, NULL);
|
||||
_cleanup_free_ char *r = strv_join((char **)input_table_multiple, NULL);
|
||||
assert_se(r);
|
||||
assert_se(streq(r, "one two three"));
|
||||
|
||||
s = strv_join((char **)input_table_one, ", ");
|
||||
_cleanup_free_ char *s = strv_join(STRV_MAKE("1", "2", "3,3"), ",");
|
||||
assert_se(s);
|
||||
assert_se(streq(s, "one"));
|
||||
assert_se(streq(s, "1,2,3,3"));
|
||||
|
||||
t = strv_join((char **)input_table_none, ", ");
|
||||
_cleanup_free_ char *t = strv_join((char **)input_table_one, ", ");
|
||||
assert_se(t);
|
||||
assert_se(streq(t, ""));
|
||||
assert_se(streq(t, "one"));
|
||||
|
||||
v = strv_join((char **)input_table_two_empties, ", ");
|
||||
_cleanup_free_ char *u = strv_join((char **)input_table_none, ", ");
|
||||
assert_se(u);
|
||||
assert_se(streq(u, ""));
|
||||
|
||||
_cleanup_free_ char *v = strv_join((char **)input_table_two_empties, ", ");
|
||||
assert_se(v);
|
||||
assert_se(streq(v, ", "));
|
||||
|
||||
w = strv_join((char **)input_table_one_empty, ", ");
|
||||
_cleanup_free_ char *w = strv_join((char **)input_table_one_empty, ", ");
|
||||
assert_se(w);
|
||||
assert_se(streq(w, ""));
|
||||
}
|
||||
|
||||
static void test_strv_join_prefix(void) {
|
||||
_cleanup_free_ char *p = NULL, *q = NULL, *r = NULL, *s = NULL, *t = NULL, *v = NULL, *w = NULL;
|
||||
|
||||
static void test_strv_join_full(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
p = strv_join_prefix((char **)input_table_multiple, ", ", "foo");
|
||||
_cleanup_free_ char *p = strv_join_full((char **)input_table_multiple, ", ", "foo", false);
|
||||
assert_se(p);
|
||||
assert_se(streq(p, "fooone, footwo, foothree"));
|
||||
|
||||
q = strv_join_prefix((char **)input_table_multiple, ";", "foo");
|
||||
_cleanup_free_ char *q = strv_join_full((char **)input_table_multiple, ";", "foo", false);
|
||||
assert_se(q);
|
||||
assert_se(streq(q, "fooone;footwo;foothree"));
|
||||
|
||||
r = strv_join_prefix((char **)input_table_multiple, NULL, "foo");
|
||||
_cleanup_free_ char *r = strv_join_full(STRV_MAKE("a", "a;b", "a:c"), ";", NULL, true);
|
||||
assert_se(r);
|
||||
assert_se(streq(r, "fooone footwo foothree"));
|
||||
assert_se(streq(r, "a;a\\;b;a:c"));
|
||||
|
||||
s = strv_join_prefix((char **)input_table_one, ", ", "foo");
|
||||
_cleanup_free_ char *s = strv_join_full(STRV_MAKE("a", "a;b", "a;;c", ";", ";x"), ";", NULL, true);
|
||||
assert_se(s);
|
||||
assert_se(streq(s, "fooone"));
|
||||
assert_se(streq(s, "a;a\\;b;a\\;\\;c;\\;;\\;x"));
|
||||
|
||||
t = strv_join_prefix((char **)input_table_none, ", ", "foo");
|
||||
_cleanup_free_ char *t = strv_join_full(STRV_MAKE("a", "a;b", "a:c", ";"), ";", "=", true);
|
||||
assert_se(t);
|
||||
assert_se(streq(t, ""));
|
||||
assert_se(streq(t, "=a;=a\\;b;=a:c;=\\;"));
|
||||
t = mfree(t);
|
||||
|
||||
v = strv_join_prefix((char **)input_table_two_empties, ", ", "foo");
|
||||
_cleanup_free_ char *u = strv_join_full((char **)input_table_multiple, NULL, "foo", false);
|
||||
assert_se(u);
|
||||
assert_se(streq(u, "fooone footwo foothree"));
|
||||
|
||||
_cleanup_free_ char *v = strv_join_full((char **)input_table_one, ", ", "foo", false);
|
||||
assert_se(v);
|
||||
assert_se(streq(v, "foo, foo"));
|
||||
assert_se(streq(v, "fooone"));
|
||||
|
||||
w = strv_join_prefix((char **)input_table_one_empty, ", ", "foo");
|
||||
_cleanup_free_ char *w = strv_join_full((char **)input_table_none, ", ", "foo", false);
|
||||
assert_se(w);
|
||||
assert_se(streq(w, "foo"));
|
||||
assert_se(streq(w, ""));
|
||||
|
||||
_cleanup_free_ char *x = strv_join_full((char **)input_table_two_empties, ", ", "foo", false);
|
||||
assert_se(x);
|
||||
assert_se(streq(x, "foo, foo"));
|
||||
|
||||
_cleanup_free_ char *y = strv_join_full((char **)input_table_one_empty, ", ", "foo", false);
|
||||
assert_se(y);
|
||||
assert_se(streq(y, "foo"));
|
||||
}
|
||||
|
||||
static void test_strv_unquote(const char *quoted, char **list) {
|
||||
@@ -995,7 +1008,7 @@ int main(int argc, char *argv[]) {
|
||||
test_strv_find_prefix();
|
||||
test_strv_find_startswith();
|
||||
test_strv_join();
|
||||
test_strv_join_prefix();
|
||||
test_strv_join_full();
|
||||
|
||||
test_strv_unquote(" foo=bar \"waldo\" zzz ", STRV_MAKE("foo=bar", "waldo", "zzz"));
|
||||
test_strv_unquote("", STRV_MAKE_EMPTY);
|
||||
|
||||
Reference in New Issue
Block a user