<div dir="ltr"><div><br></div>Hello<div><br></div><div>I just came across a problem with an innocuous looking line of code in a new module I have been working on:</div><div><br></div><div>





<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span></span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">if</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> (tmp_str.len == </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(180,36,25)">0</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">        </span></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;background-color:rgb(135,138,4)">ngx_str_se</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">t(&tmp_str, </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(180,36,25)">"/"</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">);</span></p><p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p>The modification of tmp_str.data to '/' was always being made, but the length wasn't if the test failed. This turns out to be caused by the style used in the definition of the ngx_str_set macro.</div><div><br><div>Altering this macro definition (and ngx_str_null which is similar) would protect against this:</div><div><br></div><div>





<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>--- a/ports/netflix/nginx/files/nginx/src/core/ngx_string.h</b></span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>+++ b/ports/netflix/nginx/files/nginx/src/core/ngx_string.h</b></span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,174,187)">@@ -40,8 +40,9 @@</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> typedef struct {</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>#define ngx_string(str) <span class="gmail-Apple-converted-space">    </span>{ sizeof(str) - 1, (u_char *) str }</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>#define ngx_null_string <span class="gmail-Apple-converted-space">    </span>{ 0, NULL }</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>#define ngx_str_set(str, text) <span class="gmail-Apple-converted-space">                                              </span>\</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(180,36,25)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">-<span class="gmail-Apple-converted-space">    </span>(str)->len = sizeof(text) - 1; (str)->data = (u_char *) text</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(180,36,25)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">-#define ngx_str_null(str) <span class="gmail-Apple-converted-space">  </span>(str)->len = 0; (str)->data = NULL</span></p>
<p class="gmail-p3" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(47,180,29)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">+<span class="gmail-Apple-converted-space">    </span>do { (str)->len = sizeof(text) - 1; (str)->data = (u_char *) text; } while (0)</span></p>
<p class="gmail-p3" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(47,180,29)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">+#define ngx_str_null(str)<span class="gmail-Apple-converted-space">                                                    </span>\</span></p>
<p class="gmail-p3" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(47,180,29)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">+<span class="gmail-Apple-converted-space">    </span>do { (str)->len = 0; (str)->data = NULL; } while (0)</span></p>
<p class="gmail-p1" style="margin:0px;font:11px Menlo;color:rgb(0,0,0);min-height:13px"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span></span></p><p class="gmail-p4" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px">






</p><p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>#define ngx_tolower(c)<span class="gmail-Apple-converted-space">      </span>(u_char) ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c)</span></p><p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p>I haven't looked further to see if others would benefit from such a change; figured I would run by you first</div><div><br></div><div>TIA</div><div><br></div><div>Chris</div></div></div>