On Thu, Nov 07, 2013 at 05:00:25PM -0800, John Johansen wrote:
> Its good as far as it goes, but I really want at least a warning for the
> embedded \a, and would like to settle our plans a little for the extended
> syntax so we can make sure the syntax for the aare is what we want.

Alright, here's the updated patch which adds a warning when something
that does not need to be quoted has a preceding quote.

Signed-off-by: Steve Beattie <[email protected]>
---
 parser/parser_regex.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

Index: b/parser/parser_regex.c
===================================================================
--- a/parser/parser_regex.c
+++ b/parser/parser_regex.c
@@ -329,6 +329,12 @@ static pattern_t convert_aaregex_to_pcre
                        // fall through to default
 
                default:
+                       if (bEscape) {
+                               /* quoting mark used for something that
+                                * does not need to be quoted; give a warning */
+                               pwarn("Character %c was quoted unnecessarily, "
+                                     "dropped preceding quote ('\\') 
character\n", *sptr);
+                       }
                        STORE(sptr, dptr, 1);
                        break;
                }       /* switch (*sptr) */
@@ -344,6 +350,12 @@ static pattern_t convert_aaregex_to_pcre
                       progname);
        }
 
+       if ((error == e_no_error) && bEscape) {
+               /* trailing backslash quote */
+               error = e_parse_error;
+               PERROR(_("%s: Regex error: trailing '\\' escape character\n"),
+                      progname);
+       }
        /* anchor end and terminate pattern string */
        if ((error == e_no_error) && anchor) {
                STORE("$" , dptr, 1);
@@ -1304,11 +1316,11 @@ static int test_aaregex_to_pcre(void)
 
        MY_REGEX_TEST("/most/basic/test", "/most/basic/test", ePatternBasic);
 
-       MY_REGEX_TEST("\\", "\\", ePatternBasic);
+       MY_REGEX_FAIL_TEST("\\");
        MY_REGEX_TEST("\\\\", "\\\\", ePatternBasic);
-       MY_REGEX_TEST("\\blort", "\\blort", ePatternBasic);
+       MY_REGEX_TEST("\\blort", "blort", ePatternBasic);
        MY_REGEX_TEST("\\\\blort", "\\\\blort", ePatternBasic);
-       MY_REGEX_TEST("blort\\", "blort\\", ePatternBasic);
+       MY_REGEX_FAIL_TEST("blort\\");
        MY_REGEX_TEST("blort\\\\", "blort\\\\", ePatternBasic);
        MY_REGEX_TEST("*", "[^/\\x00]*", ePatternRegex);
        MY_REGEX_TEST("blort*", "blort[^/\\x00]*", ePatternRegex);

-- 
Steve Beattie
<[email protected]>
http://NxNW.org/~steve/

Attachment: signature.asc
Description: Digital signature

-- 
AppArmor mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/apparmor

Reply via email to