Skip to content

Commit

Permalink
clang analysis fixes, assert arc4random buffer in init,
Browse files Browse the repository at this point in the history
no check for already checked delegation pointer in iterator,
in testcode check for NULL packet matches, in perf do not copy
from NULL start list when growing capacity.  Adjust host and file
only when present in test header read to please checker.  In
testcode for unknown macro operand give zero result. Initialise the
passed argv array in test code.  In test code add EDNS data
segment copy only when nonempty.


git-svn-id: file:///svn/unbound/trunk@5070 be551aaa-1e26-0410-a405-d3ace91eadb9
  • Loading branch information
wcawijngaards committed Jan 24, 2019
1 parent 37361a1 commit d48abb9
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 11 deletions.
1 change: 1 addition & 0 deletions compat/arc4random.c
Expand Up @@ -140,6 +140,7 @@ fallback_getentropy_urandom(void *buf, size_t len)
static inline void
_rs_init(u_char *buf, size_t n)
{
assert(buf);
if (n < KEYSZ + IVSZ)
return;

Expand Down
8 changes: 8 additions & 0 deletions doc/Changelog
Expand Up @@ -2,6 +2,14 @@
- Newer aclocal and libtoolize used for generating configure scripts,
aclocal 1.16.1 and libtoolize 2.4.6.
- Fix unit test for python 3.7 new keyword 'async'.
- clang analysis fixes, assert arc4random buffer in init,
no check for already checked delegation pointer in iterator,
in testcode check for NULL packet matches, in perf do not copy
from NULL start list when growing capacity. Adjust host and file
only when present in test header read to please checker. In
testcode for unknown macro operand give zero result. Initialise the
passed argv array in test code. In test code add EDNS data
segment copy only when nonempty.

23 January 2018: Wouter
- Patch from Manabu Sonoda with tls-ciphers and tls-ciphersuites
Expand Down
2 changes: 1 addition & 1 deletion iterator/iterator.c
Expand Up @@ -2299,7 +2299,7 @@ processQueryTargets(struct module_qstate* qstate, struct iter_qstate* iq,
errinf(qstate, "auth zone lookup failed, fallback is off");
return error_response(qstate, id, LDNS_RCODE_SERVFAIL);
}
if(iq->dp && iq->dp->auth_dp) {
if(iq->dp->auth_dp) {
/* we wanted to fallback, but had no delegpt, only the
* auth zone generated delegpt, create an actual one */
iq->auth_zone_avoid = 1;
Expand Down
4 changes: 2 additions & 2 deletions testcode/fake_event.c
Expand Up @@ -385,7 +385,7 @@ answer_callback_from_entry(struct replay_runtime* runtime,
repinfo.addrlen = pend->addrlen;
memcpy(&repinfo.addr, &pend->addr, pend->addrlen);
if(!pend->serviced) {
if(entry->reply_list->next &&
if(entry && entry->reply_list->next &&
pend->tcp_pkt_counter < count_reply_packets(entry)) {
/* go to next packet next time */
pend->tcp_pkt_counter++;
Expand Down Expand Up @@ -509,7 +509,7 @@ fake_pending_callback(struct replay_runtime* runtime,
repinfo.addrlen = p->addrlen;
memcpy(&repinfo.addr, &p->addr, p->addrlen);
if(!p->serviced) {
if(todo->match->reply_list->next && !error &&
if(todo->match && todo->match->reply_list->next && !error &&
p->tcp_pkt_counter < count_reply_packets(todo->match)) {
/* go to next packet next time */
p->tcp_pkt_counter++;
Expand Down
10 changes: 6 additions & 4 deletions testcode/perf.c
Expand Up @@ -513,10 +513,12 @@ qlist_grow_capacity(struct perfinfo* info)
uint8_t** d = (uint8_t**)calloc(sizeof(uint8_t*), newcap);
size_t* l = (size_t*)calloc(sizeof(size_t), newcap);
if(!d || !l) fatal_exit("out of memory");
memcpy(d, info->qlist_data, sizeof(uint8_t*)*
info->qlist_capacity);
memcpy(l, info->qlist_len, sizeof(size_t)*
info->qlist_capacity);
if(info->qlist_data)
memcpy(d, info->qlist_data, sizeof(uint8_t*)*
info->qlist_capacity);
if(info->qlist_len)
memcpy(l, info->qlist_len, sizeof(size_t)*
info->qlist_capacity);
free(info->qlist_data);
free(info->qlist_len);
info->qlist_data = d;
Expand Down
14 changes: 11 additions & 3 deletions testcode/petal.c
Expand Up @@ -323,9 +323,9 @@ file_name_is_safe(char* s)
return 1;
}

/** adjust host and filename */
/** adjust host */
static void
adjust_host_file(char* host, char* file)
adjust_host(char* host)
{
size_t i, len;
/* remove a port number if present */
Expand All @@ -335,6 +335,13 @@ adjust_host_file(char* host, char* file)
len = strlen(host);
for(i=0; i<len; i++)
host[i] = tolower((unsigned char)host[i]);
}

/** adjust filename */
static void
adjust_file(char* file)
{
size_t i, len;
len = strlen(file);
for(i=0; i<len; i++)
file[i] = tolower((unsigned char)file[i]);
Expand Down Expand Up @@ -534,7 +541,8 @@ service_ssl(SSL* ssl, struct sockaddr_storage* from, socklen_t falen)
if(!read_http_headers(ssl, file, sizeof(file), host, sizeof(host),
&vs))
return;
adjust_host_file(host, file);
if(host[0] != 0) adjust_host(host);
if(file[0] != 0) adjust_file(file);
if(host[0] == 0 || !host_name_is_safe(host))
(void)strlcpy(host, "default", sizeof(host));
if(!file_name_is_safe(file)) {
Expand Down
1 change: 1 addition & 0 deletions testcode/replay.c
Expand Up @@ -715,6 +715,7 @@ perform_arith(double x, char op, double y, double* res)
*res = x*y;
break;
default:
*res = 0;
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions testcode/testbound.c
Expand Up @@ -344,6 +344,7 @@ main(int argc, char* argv[])

/* we do not want the test to depend on the timezone */
(void)putenv("TZ=UTC");
memset(pass_argv, 0, sizeof(pass_argv));

log_init(NULL, 0, NULL);
/* determine commandline options for the daemon */
Expand Down
3 changes: 2 additions & 1 deletion testcode/testpkts.c
Expand Up @@ -513,7 +513,8 @@ add_edns(uint8_t* pktbuf, size_t pktsize, int do_flag, uint8_t *ednsdata,
if(*pktlen + sizeof(edns) + ednslen > pktsize)
error("not enough space for EDNS OPT record");
memmove(pktbuf+*pktlen, edns, sizeof(edns));
memmove(pktbuf+*pktlen+sizeof(edns), ednsdata, ednslen);
if(ednsdata && ednslen)
memmove(pktbuf+*pktlen+sizeof(edns), ednsdata, ednslen);
sldns_write_uint16(pktbuf+10, LDNS_ARCOUNT(pktbuf)+1);
*pktlen += (sizeof(edns) + ednslen);
}
Expand Down

0 comments on commit d48abb9

Please sign in to comment.