Hi Maxim,<br><br>Thanks for your comments. I thought that "%*s" in the comments above function "ngx_sprintf" is meant to be used for right alignment. And it turns out to be my own misunderstanding.<br>
<br>Gary<br><br><div class="gmail_quote">On Tue, Aug 10, 2010 at 5:07 PM, Maxim Dounin <span dir="ltr"><<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hello!<br>
<div class="im"><br>
On Tue, Aug 10, 2010 at 12:07:30PM +0800, Gary Hu wrote:<br>
<br>
> I found a defect in function "ngx_vslprintf”which doesn't support right<br>
> alignment format of a string, such as "%40s", as purported in the comments<br>
> right above the function "ngx_sprintf" in file "src/core/ngx_string.c".<br>
<br>
</div>It is not clear why you think it should be supported and no<br>
support is a bug. Both comments and code agree that it's not<br>
supported.<br>
<br>
Additionally, it's not clear why do you think it should be<br>
supported for %s, but not for %*s, %V and %v.<br>
<br>
And some patch comments just for completeness:<br>
<div class="im"><br>
> The following is my suggested fix in function "ngx_vslprintf ":<br>
><br>
><br>
><br>
> ......<br>
><br>
> case 's':<br>
><br>
> p = va_arg(args, u_char *);<br>
><br>
><br>
><br>
> //<br>
><br>
> // Added by Gary Hu<br>
><br>
> //<br>
<br>
</div>You may want to use diff -u in the future for submitting patches.<br>
<div class="im"><br>
> size_t sublen;<br>
><br>
> size_t padlen;<br>
<br>
</div>Please follow nginx style when submitting patches. In particular,<br>
please avoid declaring variables in function body. And note that<br>
nobody stops you from reusing len for padlen, and slen for sublen.<br>
So basically declared variables aren't needed.<br>
<br>
><br>
> sublen = ngx_strlen(p);<br>
<br>
This will likely cause SIGSEGV/SIGBUS for %*s as p isn't null<br>
terminated in this case.<br>
<div class="im"><br>
><br>
><br>
><br>
> /* Add padding whitespaces to the output buffer to achieve<br>
> right alignment*/<br>
><br>
> if (width > 0 && width > sublen)<br>
<br>
</div>Check "width > 0" is useless as both width and sublen are<br>
unsigned.<br>
<div class="im"><br>
> {<br>
><br>
> padlen = ngx_min(((size_t) (last - buf)), width - sublen<br>
> );<br>
><br>
> ngx_memset(buf, ' ', padlen);<br>
><br>
> buf += padlen;<br>
><br>
> }<br>
><br>
> //<br>
><br>
> // End added by Gary Hu<br>
><br>
> //<br>
<br>
</div>Maxim Dounin<br>
<br>
_______________________________________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
<a href="http://nginx.org/mailman/listinfo/nginx-devel" target="_blank">http://nginx.org/mailman/listinfo/nginx-devel</a><br>
</blockquote></div><br>