image_filter enhancement

Maxim Dounin mdounin at mdounin.ru
Wed Dec 5 14:43:13 UTC 2012


Hello!

On Tue, Dec 04, 2012 at 06:39:11PM +0400, Ruslan Khusnullin wrote:

> On Tue, Dec 4, 2012 at 5:08 PM, Maxim Dounin <mdounin at mdounin.ru> wrote:
> >> -    n = ngx_atoi(value->data, value->len);
> >> +    if (ngx_strcmp(value->data, "center") == 0) {
> >> +        return NGX_HTTP_IMAGE_OFFSET_CENTER;
> ...
> > I'm not happy with this change as it degrades performance of other
> ...
> 
> Is it safe to do ngx_strcmp (ngx_str_t.data, "string")? As far as I
> know ngx_str_t.data may have no zero at the end.

In the code in question ngx_strcmp() is ok as long as it's used on 
image_filter_crop_offset values, as they are null-terminated due 
to zero flag set during complex value compilation (and that's why 
I missed it in my review...).

It's not safe for other values though, and as the function is used 
for all values - it needs fixing.

Thanks for noting this.

> I always do
> ngx_strncmp (ngx_str_t.data, "string", ngx_str_t.len). Does it make
> sense?

Correct test for non-null-terminated string is

    s.len == sizeof("string") - 1
    && ngx_strncmp(s.data, "string", sizeof("string") - 1)

With your code string "st" will result in match, while you 
probably don't want it to.

-- 
Maxim Dounin
http://nginx.com/support.html



More information about the nginx-devel mailing list