@@ -43,7 +43,7 @@ static ngx_int_t ngx_http_lua_set_by_lua_init(ngx_http_request_t *r);
4343#endif
4444
4545static u_char * ngx_http_lua_gen_chunk_name (ngx_conf_t * cf , const char * tag ,
46- size_t tag_len );
46+ size_t tag_len , size_t * chunkname_len );
4747static ngx_int_t ngx_http_lua_conf_read_lua_token (ngx_conf_t * cf ,
4848 ngx_http_lua_block_parser_ctx_t * ctx );
4949static u_char * ngx_http_lua_strlstrn (u_char * s1 , u_char * last , u_char * s2 ,
@@ -271,13 +271,15 @@ ngx_http_lua_set_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
271271
272272 filter_data -> size = filter .size ;
273273
274- p = ngx_palloc (cf -> pool , NGX_HTTP_LUA_INLINE_KEY_LEN + 1 );
274+ p = ngx_palloc (cf -> pool ,
275+ sizeof ("set_by_lua" ) + NGX_HTTP_LUA_INLINE_KEY_LEN );
275276 if (p == NULL ) {
276277 return NGX_CONF_ERROR ;
277278 }
278279
279280 filter_data -> key = p ;
280281
282+ p = ngx_copy (p , "set_by_lua" , sizeof ("set_by_lua" ) - 1 );
281283 p = ngx_copy (p , NGX_HTTP_LUA_INLINE_TAG , NGX_HTTP_LUA_INLINE_TAG_LEN );
282284 p = ngx_http_lua_digest_hex (p , value [2 ].data , value [2 ].len );
283285 * p = '\0' ;
@@ -448,6 +450,7 @@ ngx_http_lua_rewrite_by_lua_block(ngx_conf_t *cf, ngx_command_t *cmd,
448450char *
449451ngx_http_lua_rewrite_by_lua (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
450452{
453+ size_t chunkname_len ;
451454 u_char * p , * chunkname ;
452455 ngx_str_t * value ;
453456 ngx_http_lua_main_conf_t * lmcf ;
@@ -482,7 +485,8 @@ ngx_http_lua_rewrite_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
482485
483486 if (cmd -> post == ngx_http_lua_rewrite_handler_inline ) {
484487 chunkname = ngx_http_lua_gen_chunk_name (cf , "rewrite_by_lua" ,
485- sizeof ("rewrite_by_lua" ) - 1 );
488+ sizeof ("rewrite_by_lua" ) - 1 ,
489+ & chunkname_len );
486490 if (chunkname == NULL ) {
487491 return NGX_CONF_ERROR ;
488492 }
@@ -493,13 +497,15 @@ ngx_http_lua_rewrite_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
493497
494498 llcf -> rewrite_src .value = value [1 ];
495499
496- p = ngx_palloc (cf -> pool , NGX_HTTP_LUA_INLINE_KEY_LEN + 1 );
500+ p = ngx_palloc (cf -> pool ,
501+ chunkname_len + NGX_HTTP_LUA_INLINE_KEY_LEN + 1 );
497502 if (p == NULL ) {
498503 return NGX_CONF_ERROR ;
499504 }
500505
501506 llcf -> rewrite_src_key = p ;
502507
508+ p = ngx_copy (p , chunkname , chunkname_len );
503509 p = ngx_copy (p , NGX_HTTP_LUA_INLINE_TAG , NGX_HTTP_LUA_INLINE_TAG_LEN );
504510 p = ngx_http_lua_digest_hex (p , value [1 ].data , value [1 ].len );
505511 * p = '\0' ;
@@ -562,6 +568,7 @@ ngx_http_lua_access_by_lua_block(ngx_conf_t *cf, ngx_command_t *cmd,
562568char *
563569ngx_http_lua_access_by_lua (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
564570{
571+ size_t chunkname_len ;
565572 u_char * p , * chunkname ;
566573 ngx_str_t * value ;
567574 ngx_http_lua_main_conf_t * lmcf ;
@@ -592,7 +599,8 @@ ngx_http_lua_access_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
592599
593600 if (cmd -> post == ngx_http_lua_access_handler_inline ) {
594601 chunkname = ngx_http_lua_gen_chunk_name (cf , "access_by_lua" ,
595- sizeof ("access_by_lua" ) - 1 );
602+ sizeof ("access_by_lua" ) - 1 ,
603+ & chunkname_len );
596604 if (chunkname == NULL ) {
597605 return NGX_CONF_ERROR ;
598606 }
@@ -603,13 +611,15 @@ ngx_http_lua_access_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
603611
604612 llcf -> access_src .value = value [1 ];
605613
606- p = ngx_palloc (cf -> pool , NGX_HTTP_LUA_INLINE_KEY_LEN + 1 );
614+ p = ngx_palloc (cf -> pool ,
615+ chunkname_len + NGX_HTTP_LUA_INLINE_KEY_LEN + 1 );
607616 if (p == NULL ) {
608617 return NGX_CONF_ERROR ;
609618 }
610619
611620 llcf -> access_src_key = p ;
612621
622+ p = ngx_copy (p , chunkname , chunkname_len );
613623 p = ngx_copy (p , NGX_HTTP_LUA_INLINE_TAG , NGX_HTTP_LUA_INLINE_TAG_LEN );
614624 p = ngx_http_lua_digest_hex (p , value [1 ].data , value [1 ].len );
615625 * p = '\0' ;
@@ -672,6 +682,7 @@ ngx_http_lua_content_by_lua_block(ngx_conf_t *cf, ngx_command_t *cmd,
672682char *
673683ngx_http_lua_content_by_lua (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
674684{
685+ size_t chunkname_len ;
675686 u_char * p ;
676687 u_char * chunkname ;
677688 ngx_str_t * value ;
@@ -706,7 +717,8 @@ ngx_http_lua_content_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
706717
707718 if (cmd -> post == ngx_http_lua_content_handler_inline ) {
708719 chunkname = ngx_http_lua_gen_chunk_name (cf , "content_by_lua" ,
709- sizeof ("content_by_lua" ) - 1 );
720+ sizeof ("content_by_lua" ) - 1 ,
721+ & chunkname_len );
710722 if (chunkname == NULL ) {
711723 return NGX_CONF_ERROR ;
712724 }
@@ -719,13 +731,15 @@ ngx_http_lua_content_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
719731
720732 llcf -> content_src .value = value [1 ];
721733
722- p = ngx_palloc (cf -> pool , NGX_HTTP_LUA_INLINE_KEY_LEN + 1 );
734+ p = ngx_palloc (cf -> pool ,
735+ chunkname_len + NGX_HTTP_LUA_INLINE_KEY_LEN + 1 );
723736 if (p == NULL ) {
724737 return NGX_CONF_ERROR ;
725738 }
726739
727740 llcf -> content_src_key = p ;
728741
742+ p = ngx_copy (p , chunkname , chunkname_len );
729743 p = ngx_copy (p , NGX_HTTP_LUA_INLINE_TAG , NGX_HTTP_LUA_INLINE_TAG_LEN );
730744 p = ngx_http_lua_digest_hex (p , value [1 ].data , value [1 ].len );
731745 * p = '\0' ;
@@ -795,6 +809,7 @@ ngx_http_lua_log_by_lua_block(ngx_conf_t *cf, ngx_command_t *cmd,
795809char *
796810ngx_http_lua_log_by_lua (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
797811{
812+ size_t chunkname_len ;
798813 u_char * p , * chunkname ;
799814 ngx_str_t * value ;
800815 ngx_http_lua_main_conf_t * lmcf ;
@@ -825,7 +840,8 @@ ngx_http_lua_log_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
825840
826841 if (cmd -> post == ngx_http_lua_log_handler_inline ) {
827842 chunkname = ngx_http_lua_gen_chunk_name (cf , "log_by_lua" ,
828- sizeof ("log_by_lua" ) - 1 );
843+ sizeof ("log_by_lua" ) - 1 ,
844+ & chunkname_len );
829845 if (chunkname == NULL ) {
830846 return NGX_CONF_ERROR ;
831847 }
@@ -836,13 +852,15 @@ ngx_http_lua_log_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
836852
837853 llcf -> log_src .value = value [1 ];
838854
839- p = ngx_palloc (cf -> pool , NGX_HTTP_LUA_INLINE_KEY_LEN + 1 );
855+ p = ngx_palloc (cf -> pool ,
856+ chunkname_len + NGX_HTTP_LUA_INLINE_KEY_LEN + 1 );
840857 if (p == NULL ) {
841858 return NGX_CONF_ERROR ;
842859 }
843860
844861 llcf -> log_src_key = p ;
845862
863+ p = ngx_copy (p , chunkname , chunkname_len );
846864 p = ngx_copy (p , NGX_HTTP_LUA_INLINE_TAG , NGX_HTTP_LUA_INLINE_TAG_LEN );
847865 p = ngx_http_lua_digest_hex (p , value [1 ].data , value [1 ].len );
848866 * p = '\0' ;
@@ -936,13 +954,17 @@ ngx_http_lua_header_filter_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
936954 /* Don't eval nginx variables for inline lua code */
937955 llcf -> header_filter_src .value = value [1 ];
938956
939- p = ngx_palloc (cf -> pool , NGX_HTTP_LUA_INLINE_KEY_LEN + 1 );
957+ p = ngx_palloc (cf -> pool ,
958+ sizeof ("header_filter_by_lua" ) +
959+ NGX_HTTP_LUA_INLINE_KEY_LEN + 1 );
940960 if (p == NULL ) {
941961 return NGX_CONF_ERROR ;
942962 }
943963
944964 llcf -> header_filter_src_key = p ;
945965
966+ p = ngx_copy (p , "header_filter_by_lua" ,
967+ sizeof ("header_filter_by_lua" ) - 1 );
946968 p = ngx_copy (p , NGX_HTTP_LUA_INLINE_TAG , NGX_HTTP_LUA_INLINE_TAG_LEN );
947969 p = ngx_http_lua_digest_hex (p , value [1 ].data , value [1 ].len );
948970 * p = '\0' ;
@@ -1036,13 +1058,16 @@ ngx_http_lua_body_filter_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
10361058 /* Don't eval nginx variables for inline lua code */
10371059 llcf -> body_filter_src .value = value [1 ];
10381060
1039- p = ngx_palloc (cf -> pool , NGX_HTTP_LUA_INLINE_KEY_LEN + 1 );
1061+ p = ngx_palloc (cf -> pool ,
1062+ sizeof ("body_filter_by_lua" ) +
1063+ NGX_HTTP_LUA_INLINE_KEY_LEN + 1 );
10401064 if (p == NULL ) {
10411065 return NGX_CONF_ERROR ;
10421066 }
10431067
10441068 llcf -> body_filter_src_key = p ;
10451069
1070+ p = ngx_copy (p , "body_filter_by_lua" , sizeof ("body_filter_by_lua" ) - 1 );
10461071 p = ngx_copy (p , NGX_HTTP_LUA_INLINE_TAG , NGX_HTTP_LUA_INLINE_TAG_LEN );
10471072 p = ngx_http_lua_digest_hex (p , value [1 ].data , value [1 ].len );
10481073 * p = '\0' ;
@@ -1248,7 +1273,8 @@ ngx_http_lua_set_by_lua_init(ngx_http_request_t *r)
12481273
12491274
12501275static u_char *
1251- ngx_http_lua_gen_chunk_name (ngx_conf_t * cf , const char * tag , size_t tag_len )
1276+ ngx_http_lua_gen_chunk_name (ngx_conf_t * cf , const char * tag , size_t tag_len ,
1277+ size_t * chunkname_len )
12521278{
12531279 u_char * p , * out ;
12541280 size_t len ;
@@ -1282,6 +1308,7 @@ ngx_http_lua_gen_chunk_name(ngx_conf_t *cf, const char *tag, size_t tag_len)
12821308 tag_len , tag , cf -> conf_file -> file .name .data
12831309 + cf -> conf_file -> file .name .len - p ,
12841310 p , cf -> conf_file -> line );
1311+ * chunkname_len = len ;
12851312
12861313 return out ;
12871314}
0 commit comments