[apparmor] [patch 03/12] parser: give warning for unnecessary quote characters

Seth Arnold seth.arnold at canonical.com
Fri Dec 6 03:20:37 UTC 2013


On Tue, Dec 03, 2013 at 12:12:19PM -0800, Steve Beattie wrote:
> This patch adds a warning when quote characters '\' are added
> unnecessarily, generates an error when a single quote is the last
> character in a pattern, and uncomments and corrects the relevant unit
> test cases.
> 
> Signed-off-by: Steve Beattie <steve at nxnw.org>

Acked-by: Seth Arnold <seth.arnold at canonical.com>

Thanks, these are real mind-benders of patches.

> ---
>  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);
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20131205/bec58fa6/attachment.pgp>


More information about the AppArmor mailing list