Skip to content

Commit e9cfdc0

Browse files
authored
chore: fix possible null pointer dereference found by Coverity (#223)
785 buf = p; 786 deref_ptr: Directly dereferencing pointer c. 787 if (c->addr_text.len) { 788 p = ngx_snprintf(buf, len, ", client: %V", &c->addr_text); 789 len -= p - buf; 790 buf = p; 791 } 792 CID 251610 (#1 of 1): Dereference before null check (REVERSE_INULL)check_after_deref: Null-checking c suggests that it may be null, but it has already been dereferenced on all paths leading to the check. 793 if (c && c->listening && c->listening->addr_text.len) { 794 p = ngx_snprintf(buf, len, ", server: %V", &c->listening->addr_text); 795 /* len -= p - buf; */ 796 buf = p; 797 }
1 parent c8086b6 commit e9cfdc0

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/ngx_stream_lua_timer.c

+12-9
Original file line numberDiff line numberDiff line change
@@ -784,16 +784,19 @@ ngx_stream_lua_log_timer_error(ngx_log_t *log, u_char *buf, size_t len)
784784
len -= p - buf;
785785
buf = p;
786786

787-
if (c->addr_text.len) {
788-
p = ngx_snprintf(buf, len, ", client: %V", &c->addr_text);
789-
len -= p - buf;
790-
buf = p;
791-
}
787+
if (c != NULL) {
788+
if (c->addr_text.len) {
789+
p = ngx_snprintf(buf, len, ", client: %V", &c->addr_text);
790+
len -= p - buf;
791+
buf = p;
792+
}
792793

793-
if (c && c->listening && c->listening->addr_text.len) {
794-
p = ngx_snprintf(buf, len, ", server: %V", &c->listening->addr_text);
795-
/* len -= p - buf; */
796-
buf = p;
794+
if (c->listening && c->listening->addr_text.len) {
795+
p = ngx_snprintf(buf, len, ", server: %V",
796+
&c->listening->addr_text);
797+
/* len -= p - buf; */
798+
buf = p;
799+
}
797800
}
798801

799802
return buf;

0 commit comments

Comments
 (0)