@@ -154,7 +154,8 @@ static ngx_int_t ngx_http_limit_req_handler(ngx_http_request_t *r) {
154154
155155 redisContext * c ;
156156 redisReply * reply ;
157- char Host [r -> connection -> addr_text .len ];
157+
158+ char Host [256 ];
158159 struct timeval timeout = { 1 , 500000 }; // 1.5 seconds
159160
160161 c = redisConnectWithTimeout ((char * ) redis_ip , 6379 , timeout );
@@ -206,14 +207,15 @@ static ngx_int_t ngx_http_limit_req_handler(ngx_http_request_t *r) {
206207
207208 ngx_shmtx_unlock (& ctx -> shpool -> mutex );
208209
209- memcpy (Host , r -> connection -> addr_text .data ,
210- r -> connection -> addr_text .len );
210+ const char * fmt_base = "%.*s" ;
211+ snprintf ((char * ) Host , sizeof (Host ), fmt_base ,
212+ r -> connection -> addr_text .len , r -> connection -> addr_text .data );
213+
211214 ngx_log_debug5 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
212215 "limit_req[%ui]: %i %ui.%03ui %s" , n , rc , excess / 1000 ,
213216 excess % 1000 , r -> headers_in .server .data );
214217
215- if (rc && strlen ((char * ) Host ) == r -> connection -> addr_text .len
216- && strncmp ((char * ) Host , "127.0.0.1" , 9 ) != 0 ) {
218+ if (rc && strncmp ((char * ) Host , "127.0.0.1" , 9 ) != 0 ) {
217219
218220 reply = redisCommand (c , "GET white%s" , Host );
219221 if (reply -> str == NULL ) {
@@ -251,7 +253,7 @@ static ngx_int_t ngx_http_limit_req_handler(ngx_http_request_t *r) {
251253 ngx_log_error (lrcf -> limit_log_level , r -> connection -> log , 0 ,
252254 "limiting requests, excess: %ui.%03ui by zone \"%V\" "
253255 "ip=%s ip2=%V num1=%d num2=%d" ,
254- excess / 1000 , excess % 1000 , & limit -> shm_zone -> shm .name , Host ,
256+ excess / 1000 , excess % 1000 , & limit -> shm_zone -> shm .name , ( char * ) Host ,
255257 & r -> connection -> addr_text , strlen ((char * )Host ),
256258 r -> connection -> addr_text .len );
257259
0 commit comments