Skip to content

Commit

Permalink
SonarCloud
Browse files Browse the repository at this point in the history
- Fix SonarCloud issues
  • Loading branch information
jelu committed Jun 15, 2020
1 parent 3556a80 commit 685e504
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 51 deletions.
1 change: 1 addition & 0 deletions sonar-project.properties.local
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sonar.exclusions=src/ext/**
7 changes: 4 additions & 3 deletions src/dns_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static int popular_qtypes_filter(const dns_message* m, const void* ctx)
case 255:
return 1;
default:
return 0;
break;
}
return 0;
}
Expand All @@ -164,7 +164,7 @@ static int aaaa_or_a6_filter(const dns_message* m, const void* ctx)
case T_A6:
return 1;
default:
return 0;
break;
}
return 0;
}
Expand Down Expand Up @@ -217,7 +217,7 @@ static const char* printable_dnsname(const char* name)
static char buf[MAX_QNAME_SZ];
int i;

for (i = 0; i < sizeof(buf) - 1; name++) {
for (i = 0; i < sizeof(buf) - 1;) {
if (!*name)
break;
if (isgraph(*name)) {
Expand All @@ -229,6 +229,7 @@ static const char* printable_dnsname(const char* name)
snprintf(buf + i, sizeof(buf) - i - 1, "%%%02x", (unsigned char)*name);
i += 3;
}
name++;
}
buf[i] = '\0';
return buf;
Expand Down
7 changes: 1 addition & 6 deletions src/dns_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ static int rfc1035NameUnpack(const u_char* buf, size_t sz, off_t* off, char* nam
* "(The 10 and 01 combinations are reserved for future use.)"
*/
return 3; /* reserved label/compression flags */
break;
} else {
(*off)++;
len = (size_t)c;
Expand Down Expand Up @@ -119,21 +118,17 @@ static off_t grok_question(const u_char* buf, int len, off_t offset, char* qname
x = rfc1035NameUnpack(buf, len, &offset, qname, MAX_QNAME_SZ);
if (0 != x)
return 0;
#ifndef __clang_analyzer__
if ('\0' == *qname) {
*qname = '.';
*(qname + 1) = 0;
}
#endif
/* XXX remove special characters from QNAME */
while ((t = strchr(qname, '\n')))
*t = ' ';
while ((t = strchr(qname, '\r')))
*t = ' ';
#ifndef __clang_analyzer__
for (t = qname; *t; t++)
*t = tolower(*t);
#endif
if (offset + 4 > len)
return 0;
*qtype = nptohs(buf + offset);
Expand Down Expand Up @@ -232,7 +227,7 @@ int dns_protocol_handler(const u_char* buf, int len, void* udata)
*/
while (qdcount > 0 && offset < len) {
off_t new_offset;
char t_qname[MAX_QNAME_SZ];
char t_qname[MAX_QNAME_SZ] = { 0 };
unsigned short t_qtype;
unsigned short t_qclass;
new_offset = grok_question(buf, len, offset, t_qname, &t_qtype, &t_qclass);
Expand Down
3 changes: 2 additions & 1 deletion src/hashtbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ void hash_destroy(hashtbl* tbl)
hashitem *i, *next;
int slot;
for (slot = 0; slot < tbl->modulus; slot++) {
for (i = tbl->items[slot]; i; i = next) {
for (i = tbl->items[slot]; i;) {
next = i->next;
if (tbl->keyfree)
tbl->keyfree((void*)i->key);
if (tbl->datafree)
tbl->datafree(i->data);
if (!tbl->use_arena)
xfree(i);
i = next;
}
}
if (!tbl->use_arena)
Expand Down
2 changes: 1 addition & 1 deletion src/ip_proto_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int ip_proto_iterator(const char** label)
char buf[1024];
#endif
struct protoent proto;
struct protoent* p;
struct protoent* p = 0;
if (NULL == label) {
next_iter = 0;
return largest + 1;
Expand Down
3 changes: 2 additions & 1 deletion src/parse_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,8 @@ int parse_conf(const char* file)
/*
* Go to the first non white-space character
*/
for (ret = PARSE_CONF_OK, buf = buffer, s = bufsize; *buf && s; buf++, s--) {
ret = PARSE_CONF_OK;
for (buf = buffer, s = bufsize; *buf && s; buf++, s--) {
if (*buf != ' ' && *buf != '\t') {
if (*buf == '\n' || *buf == '\r') {
ret = PARSE_CONF_EMPTY;
Expand Down
58 changes: 28 additions & 30 deletions src/pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,31 +380,7 @@ pcap_handle_tcp_segment(u_char* segment, int len, uint32_t seq, tcpstate_t* tcps
* Welcome to reassembly-land.
*/
/* find the message to which the first byte of this segment belongs */
for (m = 0;; m++) {
if (m >= MAX_TCP_MSGS) {
/* seg does not match any msgbuf; just hold on to it. */
dfprintf(1, "pcap_handle_tcp_segment: %s", "seg does not match any msgbuf");

if (seq - tcpstate->seq_start > MAX_TCP_WINDOW_SIZE) {
dfprintf(1, "pcap_handle_tcp_segment: %s", "seg is outside window; discarding");
return;
}
for (s = 0;; s++) {
if (s >= MAX_TCP_SEGS) {
dfprintf(1, "pcap_handle_tcp_segment: %s", "out of segbufs");
return;
}
if (tcpstate->segbuf[s])
continue;
tcpstate->segbuf[s] = xcalloc(1, sizeof(tcp_segbuf_t) + len);
tcpstate->segbuf[s]->seq = seq;
tcpstate->segbuf[s]->len = len;
memcpy(tcpstate->segbuf[s]->buf, segment, len);
dfprintf(1, "pcap_handle_tcp_segment: new segbuf %d: seq = %u, len = %d",
s, tcpstate->segbuf[s]->seq, tcpstate->segbuf[s]->len);
return;
}
}
for (m = 0; m < MAX_TCP_MSGS; m++) {
if (!tcpstate->msgbuf[m])
continue;
segoff = seq - tcpstate->msgbuf[m]->seq;
Expand All @@ -422,6 +398,28 @@ pcap_handle_tcp_segment(u_char* segment, int len, uint32_t seq, tcpstate_t* tcps
break;
}
}
if (m >= MAX_TCP_MSGS) {
/* seg does not match any msgbuf; just hold on to it. */
dfprintf(1, "pcap_handle_tcp_segment: %s", "seg does not match any msgbuf");

if (seq - tcpstate->seq_start > MAX_TCP_WINDOW_SIZE) {
dfprintf(1, "pcap_handle_tcp_segment: %s", "seg is outside window; discarding");
return;
}
for (s = 0; s < MAX_TCP_SEGS; s++) {
if (tcpstate->segbuf[s])
continue;
tcpstate->segbuf[s] = xcalloc(1, sizeof(tcp_segbuf_t) + len);
tcpstate->segbuf[s]->seq = seq;
tcpstate->segbuf[s]->len = len;
memcpy(tcpstate->segbuf[s]->buf, segment, len);
dfprintf(1, "pcap_handle_tcp_segment: new segbuf %d: seq = %u, len = %d",
s, tcpstate->segbuf[s]->seq, tcpstate->segbuf[s]->len);
return;
}
dfprintf(1, "pcap_handle_tcp_segment: %s", "out of segbufs");
return;
}

/* Reassembly algorithm adapted from RFC 815. */
for (i = 0; i < MAX_TCP_HOLES; i++) {
Expand Down Expand Up @@ -450,16 +448,16 @@ pcap_handle_tcp_segment(u_char* segment, int len, uint32_t seq, tcpstate_t* tcps
if (segoff > hole_start) {
/* create a new hole before the segment */
int j;
for (j = 0;; j++) {
if (j == MAX_TCP_HOLES) {
dfprintf(1, "pcap_handle_tcp_segment: %s", "out of hole descriptors");
return;
}
for (j = 0; j < MAX_TCP_HOLES; j++) {
if (tcpstate->msgbuf[m]->hole[j].len == 0) {
newhole = &tcpstate->msgbuf[m]->hole[j];
break;
}
}
if (j >= MAX_TCP_HOLES) {
dfprintf(1, "pcap_handle_tcp_segment: %s", "out of hole descriptors");
return;
}
tcpstate->msgbuf[m]->holes++;
newhole->start = hole_start;
newhole->len = segoff - hole_start;
Expand Down
14 changes: 7 additions & 7 deletions src/query_classification_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,16 @@ rfc1918_ptr(const dns_message* m)
{
char* tok = 0;
char* t;
char q[128];
char q[1024];
unsigned int i = 0;
if (m->qtype != T_PTR)
return 0;
strncpy(q, m->qname, sizeof(q) - 1);
q[sizeof(q) - 1] = '\0';
q[sizeof(q) - 1] = 0;
strncpy(q, m->qname, sizeof(q));
if (q[sizeof(q) - 1] != 0) {
// String was truncated
return 0;
}
if (NULL == (t = strstr(q, ".in-addr.arpa")))
return 0;
*t = '\0';
Expand All @@ -144,9 +148,7 @@ funny_qclass(const dns_message* m)
case C_NONE:
case C_HS:
return 0;
break;
default:
return CLASS_FUNNY_QCLASS;
break;
}
return CLASS_FUNNY_QCLASS;
Expand Down Expand Up @@ -199,9 +201,7 @@ funny_qtype(const dns_message* m)
case T_MAILA:
case T_ANY:
return 0;
break;
default:
return CLASS_FUNNY_QTYPE;
break;
}
return CLASS_FUNNY_QTYPE;
Expand Down
4 changes: 2 additions & 2 deletions src/response_time_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ int response_time_indexer(const dns_message* m)
dfprintf(2, "response_time: found q/r us:%lu, put in bucket %d (%lu-%lu usec)", us, iter, (us / bucket_size) * bucket_size, ((us / bucket_size) + 1) * bucket_size);
break;
case response_time_log10: {
double d = log10(us);
double d = log10((double)us);
if (d < 0) {
dfprintf(1, "response_time: bad log10(%lu) ret %f", us, d);
return INTERNAL_ERROR;
Expand All @@ -275,7 +275,7 @@ int response_time_indexer(const dns_message* m)
break;
}
case response_time_log2: {
double d = log2(us);
double d = log2((double)us);
if (d < 0) {
dfprintf(1, "response_time: bad log2(%lu) ret %f", us, d);
return INTERNAL_ERROR;
Expand Down

0 comments on commit 685e504

Please sign in to comment.