<p>Sean Bright has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13901">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">enum.c: Add support for regular expression flag in NAPTR record<br><br>A regular expression in a NAPTR response record can have a trailing<br>'i' flag to indicate that the expression should be evaluated in a<br>case-insensitive way. We were not checking for that flag which caused<br>the record parsing to fail on otherwise valid input.<br><br>Although this change will initially go into Asterisk 13, 16, and 17,<br>it is my intention to replace the majority of this code in 16 and up -<br>including this fix - by changing enum.c to consume the new DNS API<br>which duplicates most of this logic already. Asterisk 13 doesn't have<br>the DNS API, so this fix will be as good as it gets.<br><br>ASTERISK-26711 #close<br>Reported by: Vitold<br><br>Change-Id: I33943a5b3e7539c6dca3a5079982ee15a08186f0<br>---<br>M main/enum.c<br>1 file changed, 13 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/01/13901/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/enum.c b/main/enum.c</span><br><span>index e003f07..17bba83 100644</span><br><span>--- a/main/enum.c</span><br><span>+++ b/main/enum.c</span><br><span>@@ -415,6 +415,7 @@</span><br><span>      int size, matchindex; /* size is the size of the backreference sub. */</span><br><span>       size_t d_len = sizeof(tempdst) - 1;</span><br><span>  regex_t preg;</span><br><span style="color: hsl(120, 100%, 40%);">+ int re_flags = REG_EXTENDED | REG_NEWLINE;</span><br><span>   regmatch_t pmatch[max_bt];</span><br><span> </span><br><span>       tech_return[0] = '\0';</span><br><span>@@ -496,13 +497,23 @@</span><br><span>        * and uses that character to find the index of the second delimiter */</span><br><span>      delim = regexp[0];</span><br><span>   delim2 = strchr(regexp + 1, delim);</span><br><span style="color: hsl(0, 100%, 40%);">-     if ((delim2 == NULL) || (regexp[regexp_len - 1] != delim)) {  /* is the second delimiter found, and is the end of the regexp a delimiter */</span><br><span style="color: hsl(120, 100%, 40%);">+   if ((delim2 == NULL)</span><br><span style="color: hsl(120, 100%, 40%);">+          || ((regexp[regexp_len - 1] != 'i' || regexp[regexp_len - 2] != delim)</span><br><span style="color: hsl(120, 100%, 40%);">+                        && regexp[regexp_len - 1] != delim)) {</span><br><span>               ast_log(LOG_WARNING, "Regex delimiter error (on \"%s\").\n", regexp);</span><br><span>            return -1;</span><br><span>   } else if (strchr((delim2 + 1), delim) == NULL) { /* if the second delimiter is found, make sure there is a third instance.  this could be the end one instead of the middle */</span><br><span>              ast_log(LOG_WARNING, "Regex delimiter error (on \"%s\").\n", regexp);</span><br><span>            return -1;</span><br><span>   }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* Make the regex case-insensitive if the 'i' flag is present. This assumes you</span><br><span style="color: hsl(120, 100%, 40%);">+        * aren't using 'i' as a delimiter which, altough dubious, does not appear to be</span><br><span style="color: hsl(120, 100%, 40%);">+   * explicitly non-compliant */</span><br><span style="color: hsl(120, 100%, 40%);">+        if (regexp[regexp_len - 1] == 'i') {</span><br><span style="color: hsl(120, 100%, 40%);">+          re_flags |= REG_ICASE;</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  pattern = regexp + 1;   /* pattern is the regex without the begining and ending delimiter */</span><br><span>         *delim2 = 0;    /* zero out the middle delimiter */</span><br><span>  subst   = delim2 + 1; /* dst substring is everything after the second delimiter. */</span><br><span>@@ -512,7 +523,7 @@</span><br><span>  * now do the regex wizardry.</span><br><span>  */</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   if (regcomp(&preg, pattern, REG_EXTENDED | REG_NEWLINE)) {</span><br><span style="color: hsl(120, 100%, 40%);">+        if (regcomp(&preg, pattern, re_flags)) {</span><br><span>                 ast_log(LOG_WARNING, "NAPTR Regex compilation error (regex = \"%s\").\n", regexp);</span><br><span>               return -1;</span><br><span>   }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13901">change 13901</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/13901"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: I33943a5b3e7539c6dca3a5079982ee15a08186f0 </div>
<div style="display:none"> Gerrit-Change-Number: 13901 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>