diff options
author | Frantisek Sumsal <frantisek@sumsal.cz> | 2023-04-15 22:22:56 +0200 |
---|---|---|
committer | Frantisek Sumsal <frantisek@sumsal.cz> | 2023-04-16 09:21:13 +0200 |
commit | 841834d9c358163308deb70642249e8b2ba76c1a (patch) | |
tree | c6fda2164099c4856c981d910668cab333030def /src/test/test-env-file.c | |
parent | 192242c986e2462c4d2ec5b3ecd6f1ac02f9c0ad (diff) | |
download | systemd-841834d9c358163308deb70642249e8b2ba76c1a.tar.gz |
test: add a couple of tests with invalid UTF-8 characters
Diffstat (limited to 'src/test/test-env-file.c')
-rw-r--r-- | src/test/test-env-file.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/test/test-env-file.c b/src/test/test-env-file.c index 461a0f0810..c8ec0e2278 100644 --- a/src/test/test-env-file.c +++ b/src/test/test-env-file.c @@ -58,7 +58,6 @@ "d= \" \\n\\t\\$\\`\\\\\n" \ "\" \n" - TEST(load_env_file_1) { _cleanup_(unlink_tempfilep) char name[] = "/tmp/test-load-env-file.XXXXXX"; assert_se(write_tmpfile(name, env_file_1) == 0); @@ -129,6 +128,25 @@ TEST(load_env_file_6) { assert_se(data[4] == NULL); } +TEST(load_env_file_invalid_utf8) { + /* Test out a couple of assignments where the key/value has an invalid + * UTF-8 character ("noncharacter") + * + * See: https://en.wikipedia.org/wiki/Universal_Character_Set_characters#Non-characters + */ + FOREACH_STRING(s, + "fo\ufffeo=bar", + "foo=b\uffffar", + "baz=hello world\ufffe") { + _cleanup_(unlink_tempfilep) char name[] = "/tmp/test-load-env-file.XXXXXX"; + assert_se(write_tmpfile(name, s) == 0); + + _cleanup_strv_free_ char **data = NULL; + assert_se(load_env_file(NULL, name, &data) == -EINVAL); + assert_se(!data); + } +} + TEST(write_and_load_env_file) { /* Make sure that our writer, parser and the shell agree on what our env var files mean */ |