res_ael: Fix pattern matching against literal '+'
authorSean Bright <sean.bright@gmail.com>
Thu, 11 Apr 2019 16:03:07 +0000 (12:03 -0400)
committerSean Bright <sean.bright@gmail.com>
Thu, 11 Apr 2019 20:10:41 +0000 (14:10 -0600)
When generating the regular expression that matches against existing
extensions, we need to escape literal characters that can also be
regular expression metacharacters. This was already being done for '*'
but we need to do the same for '+'.

In passing, remove some unreachable code - strcmp() is already run
immediately when entering extension_matches().

ASTERISK-14939 #close
Reported by: klaus3000

Change-Id: I8d2cccb3479168fba1b0a6704c52198b396468f1

res/ael/pval.c

index f927077..37d53ad 100644 (file)
@@ -759,10 +759,10 @@ static int extension_matches(pval *here, const char *exten, const char *pattern)
                                *r++ = '.';
                                *r++ = '*';
                                break;
                                *r++ = '.';
                                *r++ = '*';
                                break;
-                       case '*':
+                       case '*': /* regex metacharacter */
+                       case '+': /* regex metacharacter */
                                *r++ = '\\';
                                *r++ = '\\';
-                               *r++ = '*';
-                               break;
+                               /* fall through */
                        default:
                                *r++ = *p;
                                break;
                        default:
                                *r++ = *p;
                                break;
@@ -792,14 +792,9 @@ static int extension_matches(pval *here, const char *exten, const char *pattern)
                           exten, pattern); */
                        return 1;
                }
                           exten, pattern); */
                        return 1;
                }
-
-
-       } else {
-               if ( strcmp(exten,pattern) == 0 ) {
-                       return 1;
-               } else
-                       return 0;
        }
        }
+
+       return 0;
 }
 
 
 }