Commit graph

40 commits

Author SHA1 Message Date
Richard Maw 04c14b2541 strv: Add strv_shell_escape
This modifies the strv in-place, replacing strings with their escaped
version. It's mostly just a convenience function for when you need to
join a strv together because it's passed as a string to something, and
the separator needs escaping.
2015-08-07 15:50:43 +00:00
Richard Maw 8adaf7bd23 strv: convert strv_split_quotes into a generic strv_split_extract
strv_split_extract is to strv_split_quotes as extract_first_word was to
unquote_first_word.

Now there's extract_first_word for extracting a single argument,
extract_many_words for extracting a bounded number of arguments,
and strv_split_extract for extracting an arbitrary number of arguments.
2015-08-07 15:50:43 +00:00
Thomas Hindoe Paaboel Andersen 7d6884b65e tree-wide: fix indentation 2015-08-06 00:44:19 +02:00
Lennart Poettering 4034a06ddb util: rework word parsing and c unescaping code
When parsing words from input files, optionally automatically unescape
the passed strings, controllable via a new flags parameter.

Make use of this in tmpfiles, and port everything else over, too.

This improves parsing quite a bit, since we no longer have to process the
same string multiple times with different calls, where an earlier call
might corrupt the input for a later call.
2015-03-26 11:56:22 +01:00
Lennart Poettering e1dd6790e4 strv: ass new strv_is_uniq() and strv_reverse() calls 2014-12-19 02:07:42 +01:00
Zbigniew Jędrzejewski-Szmek ba774317ac Treat a trailing backslash as an error
Commit a2a5291b3f changed the parser to reject unfinished quoted
strings. Unfortunately it introduced an error where a trailing
backslash would case an infinite loop. Of course this must fixed, but
the question is what to to instead. Allowing trailing backslashes and
treating them as normal characters would be one option, but this seems
suboptimal. First, there would be inconsistency between handling of
quoting and of backslashes. Second, a trailing backslash is most
likely an error, at it seems better to point it out to the user than
to try to continue.

Updated rules:
ExecStart=/bin/echo \\ → OK, prints a backslash
ExecStart=/bin/echo \ → error
ExecStart=/bin/echo "x → error
ExecStart=/bin/echo "x"y → error
2014-12-18 19:26:21 -05:00
Zbigniew Jędrzejewski-Szmek 30bcc05295 test-strv: use STRV_MAKE 2014-12-18 19:26:21 -05:00
Ronny Chevalier e74aa253e9 test-strv: add test for strv_equal 2014-12-11 18:32:57 +01:00
Lennart Poettering 98940a3cd9 strv: add calls to add two entries to an strv at once 2014-12-03 18:31:51 +01:00
Lennart Poettering f88e6be5ee strv: rework strv_split_quoted() to use unquote_first_word()
This should make the unquoting scheme a bit less naive.
2014-11-10 23:45:12 +01:00
Ronny Chevalier 7bd57a87ad tests: add tests for strv.c
add tests for:
- strv_find_startswith
- strv_push_prepend
- strv_consume_prepend
2014-10-31 10:57:21 +01:00
Thomas Hindoe Paaboel Andersen bdf7026e95 test: only use assert_se
The asserts used in the tests should never be allowed to be
optimized away
2014-10-04 23:55:35 +02:00
Zbigniew Jędrzejewski-Szmek b2fadec604 Properly report invalid quoted strings
$ systemd-analyze verify trailing-g.service
[./trailing-g.service:2] Trailing garbage, ignoring.
trailing-g.service lacks ExecStart setting. Refusing.
Error: org.freedesktop.systemd1.LoadFailed: Unit trailing-g.service failed to load: Invalid argument.
Failed to create trailing-g.service/start: Invalid argument
2014-07-31 08:56:03 -04:00
Zbigniew Jędrzejewski-Szmek a2a5291b3f Reject invalid quoted strings
String which ended in an unfinished quote were accepted, potentially
with bad memory accesses.

Reject anything which ends in a unfished quote, or contains
non-whitespace characters right after the closing quote.

_FOREACH_WORD now returns the invalid character in *state. But this return
value is not checked anywhere yet.

Also, make 'word' and 'state' variables const pointers, and rename 'w'
to 'word' in various places. Things are easier to read if the same name
is used consistently.

mbiebl_> am I correct that something like this doesn't work
mbiebl_> ExecStart=/usr/bin/encfs --extpass='/bin/systemd-ask-passwd "Unlock EncFS"'
mbiebl_> systemd seems to strip of the quotes
mbiebl_> systemctl status shows
mbiebl_> ExecStart=/usr/bin/encfs --extpass='/bin/systemd-ask-password Unlock EncFS  $RootDir $MountPoint
mbiebl_> which is pretty weird
2014-07-31 04:00:31 -04:00
Zbigniew Jędrzejewski-Szmek 73381fcf54 test-strv: add test which shows access to random memory 2014-07-31 04:00:31 -04:00
Ronny Chevalier 4a336a69fd tests: add tests for strv_extendf 2014-06-19 19:59:57 -04:00
Simon Peeters e3e45d4f82 strv: multiple cleanups
- turn strv_merge into strv_extend_strv.
   appending strv b to the end of strv a instead of creating a new strv
- strv_append: remove in favor of strv_extend and strv_push.
- strv_remove: write slightly more elegant
- strv_remove_prefix: remove unused function
- strv_overlap: use strv_contains
- strv_printf: STRV_FOREACH handles NULL correctly
2014-01-05 09:16:15 -05:00
Thomas Hindoe Paaboel Andersen 5fba7bbfa4 scan-build: silence some warnings
test-fileio/test-strv:
Use the streq_ptr to make build-scan not worry about passing in a null
to a nonnull function.

test-dhcp-option:
Prevent a theoretical null pointer dereference
2013-12-12 23:08:47 +01:00
Lennart Poettering 70f75a523b util: fix handling of trailing whitespace in split_quoted()
Inspired by a patch by Lukas Nykryn.
2013-11-28 18:42:18 +01:00
Daniel Buch aed2ebfed0 test-strv: add strv_split, strv_split_newline, strv_remove_prefix 2013-11-07 01:23:55 -05:00
Lennart Poettering 897e7561a0 strv: introduce new STRV_MAKE and STRV_MAKE_EMPTY macros to create string arrays nicely on the fly 2013-10-29 20:09:16 +01:00
Lennart Poettering 250a918dc4 strv: introduce new strv_from_stdarg_alloca() macro to generate a string array from stdarg function parameters
This allows us to turn lists of strings passed in easily into string
arrays without having to allocate memory.
2013-10-29 19:53:43 +01:00
Daniel Buch 02f19706a9 test-strv.c: added STRV_FOREACH and STRV_FOREACH_BACKWARDS 2013-10-27 11:51:22 -04:00
Lennart Poettering 1731e34a4e tmpfiles: support simple specifier expansion for specified paths 2013-09-17 11:02:54 -05:00
Lennart Poettering 19f6d71077 specifier: rework specifier calls to return proper error message
Previously the specifier calls could only indicate OOM by returning
NULL. With this change they will return negative errno-style error codes
like everything else.
2013-09-17 10:06:50 -05:00
Zbigniew Jędrzejewski-Szmek a6fde35332 systemd-run: properly escape arguments
Spaces, quotes, and such, were not properly escaped. We should
write them like we read them.

https://bugs.freedesktop.org/show_bug.cgi?id=67971
2013-09-09 13:49:29 -04:00
Zbigniew Jędrzejewski-Szmek 1e64bbc156 test-strv: do not declare table to be sorted const
Segmentation fault under clang.
2013-04-05 00:31:59 -04:00
Daniel Buch 4c325b2efe test-strv.c: test STRV_FOREACH_PAIR macro 2013-03-18 21:09:02 +01:00
Daniel Buch 9f31636648 test-strv.c: ported test_specifier_printf() to _cleanup_free_ + assert_se + cleanup 2013-02-18 23:57:56 +01:00
Daniel Buch 04045d8426 test-strv.c: added OOM check for current tests
New OOM check patch:

I do assert_se() before variable is used to do correct check.
2013-02-18 23:57:48 +01:00
Daniel Buch 2f213f7493 test-strv.c: added strv_split_nulstr() test 2013-02-18 23:57:43 +01:00
Daniel Buch 7b68d618a2 test-strv.c: Changed assert() to assert_se()
test-strv.c: Indent fix
2013-02-13 20:22:12 +01:00
Daniel Buch 40857008d8 test-strv.c: added strv_append test 2013-02-13 20:22:09 +01:00
Daniel Buch 343a896935 test-strv.c: added strv_merge_concat test 2013-02-13 20:22:05 +01:00
Daniel Buch a1022300b9 test-strv.c: added strv_merge test 2013-02-13 20:21:44 +01:00
Thomas Hindoe Paaboel Andersen 10ddd913f0 tests: move strv_parse_nulstr to test-strv, and actually test it
The test was originally added with this commit message:
"ask-password: supported plymouth cached passwords"
2013-02-07 00:38:16 +01:00
Thomas Hindoe Paaboel Andersen 539ad707db test: add a few tests and tidy up
adds test of:
strv_find
strv_find_prefix
strv_overlap
strv_sort
streq_ptr
first_word

Splits tests of util.c into own file to avoid clutter as we add more.

Removed a few prints and uses _cleanup_free_ to make the tests more focused.
2013-02-06 21:15:23 +01:00
Daniel Buch 682cfdff69 test-strv.c: test strv_join added 2013-01-30 23:37:39 -05:00
Daniel Buch 3a7719d303 test-strv.c: Split tests into seperate functions
test-strv.c: Leaves main clean for additional tests
2013-01-30 23:37:39 -05:00
Lennart Poettering 379079ba6b test: test tools should still be in the src/ directory 2012-04-12 13:48:01 +02:00
Renamed from test/test-strv.c (Browse further)