Welcome! Log In Create A New Profile

Advanced

Unexpected structure of macros in ngx_string.h

Chris Newton
January 11, 2021 07:42PM
Hello

I just came across a problem with an innocuous looking line of code in a
new module I have been working on:

if (tmp_str.len == 0)

ngx_str_set(&tmp_str, "/");


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.

Altering this macro definition (and ngx_str_null which is similar) would
protect against this:

*--- a/ports/netflix/nginx/files/nginx/src/core/ngx_string.h*

*+++ b/ports/netflix/nginx/files/nginx/src/core/ngx_string.h*

@@ -40,8 +40,9 @@ typedef struct {

#define ngx_string(str) { sizeof(str) - 1, (u_char *) str }

#define ngx_null_string { 0, NULL }

#define ngx_str_set(str, text)
\

- (str)->len = sizeof(text) - 1; (str)->data = (u_char *) text

-#define ngx_str_null(str) (str)->len = 0; (str)->data = NULL

+ do { (str)->len = sizeof(text) - 1; (str)->data = (u_char *) text; }
while (0)

+#define ngx_str_null(str)
\

+ do { (str)->len = 0; (str)->data = NULL; } while (0)



#define ngx_tolower(c) (u_char) ((c >= 'A' && c <= 'Z') ? (c | 0x20)
: c)


I haven't looked further to see if others would benefit from such a change;
figured I would run by you first

TIA

Chris
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Unexpected structure of macros in ngx_string.h

Chris Newton 305 January 11, 2021 07:42PM

Re: Unexpected structure of macros in ngx_string.h

Maxim Dounin 141 January 12, 2021 07:58AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 289
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready