libselinux: label_file: handle newlines in file names
PATCH 1/1 libselinux: label_file: handle newlines in file names
From: Nick Kralevich <[email protected]>
restorecon on file names with newlines are not handled properly. Use PCRE_DOTALL so that dots in regular expressions match all characters, and don't exclude the newline character.
See https://www.mail-archive.com/[email protected]/msg02001.html
for background.
--- libselinux/src/label_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/src/label_file.c +1 -1
@@ -129,7 +129,7 @@ static int compile_regex(struct saved_data *data, struct spec *spec, const char *cp ='\0' ;/* Compile the regular expression. */ - spec->regex =pcre_compile (anchored_regex,0 , &tmperrbuf, &erroff,NULL ); + spec->regex =pcre_compile (anchored_regex,PCRE_DOTALL , &tmperrbuf, &erroff,NULL );free (anchored_regex);if (!spec->regex) {if (errbuf)
Signature · 1 line
1.9.3
Quoted 21 lines · Stephen Smalley
From: Nick Kralevich <[email protected]>
restorecon on file names with newlines are not handled properly. Use
PCRE_DOTALLso that dots in regular expressions match all characters, and don't exclude the newline character.See https://www.mail-archive.com/[email protected]/msg02001.html
for background.Change-Id I0dde8f2567305f746d19ebd75a9e2add7406eb9aSigned-off-by Stephen Smalley <[email protected]>--- libselinux/src/label_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libselinux/src/label_file.c +0
-0
libselinux/src/label_file.c static int compile_regex(struct saved_data *data, struct spec *spec, const char · line 135
Quoted 8 lines
libselinux/src/label_file.c +1
-1@@ -129,7 +129,7 @@ static int compile_regex(struct saved_data *data, struct spec *spec, const char *cp ='\0' ;/* Compile the regular expression. */ - spec->regex =pcre_compile (anchored_regex,0 , &tmperrbuf, &erroff,NULL ); + spec->regex =pcre_compile (anchored_regex,PCRE_DOTALL , &tmperrbuf, &erroff,NULL );free (anchored_regex);if (!spec->regex) {if (errbuf)
Do we need a similar change in sefcontext_compile.c? It also looks like mcstrans compiles regular expressions, but I don't think those are related to matching paths.
- Steve
Quoted 23 lines · Steve Lawrence
Quoted 22 lines · Stephen Smalley
From: Nick Kralevich <[email protected]>
restorecon on file names with newlines are not handled properly. Use
PCRE_DOTALLso that dots in regular expressions match all characters, and don't exclude the newline character.See https://www.mail-archive.com/[email protected]/msg02001.html
for background.Change-Id I0dde8f2567305f746d19ebd75a9e2add7406eb9aSigned-off-by Stephen Smalley <[email protected]>--- libselinux/src/label_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libselinux/src/label_file.c +0
-0@@ -129,7 +129,7 @@ static int compile_regex(struct saved_data *data, struct spec *spec, const char *cp ='\0' ;
Quoted 11 lines
libselinux/src/label_file.c static int compile_regex(struct saved_data *data, struct spec *spec, const char · line 135
Quoted 7 lines
libselinux/src/label_file.c +1
-1/* Compile the regular expression. */ - spec->regex =pcre_compile (anchored_regex,0 , &tmperrbuf, &erroff,NULL ); + spec->regex =pcre_compile (anchored_regex,PCRE_DOTALL , &tmperrbuf, &erroff,NULL );free (anchored_regex);if (!spec->regex) {if (errbuf)Do we need a similar change in
sefcontext_compile.c? It also looks like mcstrans compiles regular expressions, but I don't think those are related to matching paths.
Yes for sefcontext_compile.c (doesn't exist in Android's libselinux, which does not yet include the file_contexts.bin support).