Skip to content

Commit

Permalink
chore: fix possible null pointer dereference found by Coverity (#223)
Browse files Browse the repository at this point in the history
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    }
  • Loading branch information
chipitsine authored Jan 12, 2021
1 parent c8086b6 commit e9cfdc0
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/ngx_stream_lua_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,16 +784,19 @@ ngx_stream_lua_log_timer_error(ngx_log_t *log, u_char *buf, size_t len)
len -= p - buf;
buf = p;

if (c->addr_text.len) {
p = ngx_snprintf(buf, len, ", client: %V", &c->addr_text);
len -= p - buf;
buf = p;
}
if (c != NULL) {
if (c->addr_text.len) {
p = ngx_snprintf(buf, len, ", client: %V", &c->addr_text);
len -= p - buf;
buf = p;
}

if (c && c->listening && c->listening->addr_text.len) {
p = ngx_snprintf(buf, len, ", server: %V", &c->listening->addr_text);
/* len -= p - buf; */
buf = p;
if (c->listening && c->listening->addr_text.len) {
p = ngx_snprintf(buf, len, ", server: %V",
&c->listening->addr_text);
/* len -= p - buf; */
buf = p;
}
}

return buf;
Expand Down

0 comments on commit e9cfdc0

Please sign in to comment.