udev-rules: all values can contain escaped double quotes now#6890
Merged
keszybz merged 1 commit intosystemd:masterfrom Sep 28, 2017
Merged
udev-rules: all values can contain escaped double quotes now#6890keszybz merged 1 commit intosystemd:masterfrom
keszybz merged 1 commit intosystemd:masterfrom
Conversation
Member
|
Can you please add some tests for this? We have a pretty good set of test for udev rules, and a tricky change like this is much safer with proper CI. |
Contributor
Author
|
Sure, I'll do that. |
73094fc to
89f15a5
Compare
Contributor
Author
|
@keszybz : done |
keszybz
reviewed
Sep 26, 2017
Member
keszybz
left a comment
There was a problem hiding this comment.
Please incorporate the following test:
diff --cc test/udev-test.pl
index f1326a3d44,f1326a3d44..e8cc85a6df
--- test/udev-test.pl
+++ test/udev-test.pl
@@@ -349,6 -349,6 +349,14 @@@ SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -
EOF
},
{
++ desc => "program arguments combined with escaped double quotes, part 3",
++ devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
++ exp_name => "foo2" ,
++ rules => <<EOF
++SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'printf \\\"%s %s\\\" \\\"foo1 foo2\\\" \\\"foo3\\\"| grep \\\"foo1 foo2\\\"'", KERNEL=="sda5", SYMLINK+="%c{2}"
++EOF
++ },
++ {
desc => "characters before the %c{N} substitution",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
exp_name => "my-foo9" ,This fails here :(
src/udev/udev-event.c
Outdated
| while (pos != NULL && pos[0] != '\0') { | ||
| if (pos[0] == '\'') { | ||
| /* do not separate quotes */ | ||
| if (pos[0] == '\'' || pos[0] == '"') { |
Contributor
Author
There was a problem hiding this comment.
Regarding your failing test case: good catch ! actually in the test cases "%s" needs to be escaped as well otherwise udev will do its string substitutions.
I'll fix that.
Thanks !
This is primarly useful to support escaped double quotes in PROGRAM or
IMPORT{program} directives.
The only possibilty before this patch was to use an external shell script but
this seems too cumbersome for trivial logics such as
PROGRAM=="/bin/sh -c 'FOO=\"%s{model}\"; echo ${FOO:0:4}'"
or any similar shell constructs that needs to deals with patterns including
whitespaces.
As it's the case for single quote and for directives running a program, words
within escaped double quotes will be considered as a single argument.
Fixes: systemd#6835
89f15a5 to
8a247d5
Compare
Contributor
Author
|
@keszybz new version force pushed. Thanks for your review ! |
SergioAtSUSE
pushed a commit
to SergioAtSUSE/systemd_systemd
that referenced
this pull request
Jun 7, 2018
…#6890) This is primarly useful to support escaped double quotes in PROGRAM or IMPORT{program} directives. The only possibilty before this patch was to use an external shell script but this seems too cumbersome for trivial logics such as PROGRAM=="/bin/sh -c 'FOO=\"%s{model}\"; echo ${FOO:0:4}'" or any similar shell constructs that needs to deals with patterns including whitespaces. As it's the case for single quote and for directives running a program, words within escaped double quotes will be considered as a single argument. Fixes: systemd#6835 (cherry picked from commit 7e760b7)
Werkov
pushed a commit
to Werkov/systemd
that referenced
this pull request
Nov 27, 2018
…#6890) This is primarly useful to support escaped double quotes in PROGRAM or IMPORT{program} directives. The only possibilty before this patch was to use an external shell script but this seems too cumbersome for trivial logics such as PROGRAM=="/bin/sh -c 'FOO=\"%s{model}\"; echo ${FOO:0:4}'" or any similar shell constructs that needs to deals with patterns including whitespaces. As it's the case for single quote and for directives running a program, words within escaped double quotes will be considered as a single argument. Fixes: systemd#6835 (cherry picked from commit 7e760b7)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is primarly useful to support escaped double quotes in PROGRAM or
IMPORT{program} directives.
The only possibilty before this patch was to use an external shell script but
this seems too cumbersome for trivial logics.
Fixes: #6835