Opened 5 years ago

Closed 5 years ago

#866 closed defect (invalid)

ngx_pstrdup() and ngx_copy() problems

Reported by: Sem-ym@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.9.x
Keywords: ngx_copy, ngx_pstrdup, stings Cc: sem33@…
uname -a: any
nginx -V: any

Description

Hi.

It looks like strings are supposed to finish with '\0' char to be compatible with C strings. So ngx_pstrdup() must allocate and copy len+1, not just len.

ngx_copy() returns different values for different preprocessor conditions.

I don't know how to attach a file here, so patch could be found here: https://github.com/sem-hub/nginx/commit/4f2202ae8f17dfe086420a28e6e08d607528c53a

Attachments (1)

ngx_strings.patch (838 bytes ) - added by Sem-ym@… 5 years ago.
patch

Download all attachments as: .zip

Change History (2)

by Sem-ym@…, 5 years ago

Attachment: ngx_strings.patch added

patch

comment:1 by Maxim Dounin, 5 years ago

Resolution: invalid
Status: newclosed

No, your assumptions are wrong. Strings in nginx are not expected to be null-terminated in general. The ngx_pstrdup() function is expected to duplicate the string passed, exactly, and this is what it currently does. The change to ngx_copy() is also wrong, you've missed dst++ in the loop.

Please also see http://nginx.org/en/docs/contributing_changes.html.

Note: See TracTickets for help on using tickets.