@cryptotaxi247 / netdata-1 / commits / 3601202dc

bug fixes detected by static code analysis using Coverity.com

Costa Tsaousis (ktsaou) committed Jun 14, 2016 at 02:41 UTC 3601202dc6b9b7102df746ae600baf8bf20b4da3
9 files changed +26 -15
src/common.c
+3 -1
@@ -851,6 +851,8 @@ int snprintfz(char *dst, size_t n, const char *fmt, ...) {
851 va_list args;
852
853 va_start(args, fmt);
854 - return vsnprintfz(dst, n, fmt, args);
854 + int ret = vsnprintfz(dst, n, fmt, args);
855 va_end(args);
856 +
857 + return ret;
858 }
src/daemon.c
+1 -1
@@ -307,7 +307,7 @@ int become_daemon(int dont_fork, int close_all_files, const char *user, const ch
307 }
308
309 if(user && *user) {
310 - if(become_user(user, (*access_fd)?*access_fd:-1, output_fd, error_fd, pidfd) != 0) {
310 + if(become_user(user, (access_fd)?*access_fd:-1, output_fd, error_fd, pidfd) != 0) {
311 error("Cannot become user '%s'. Continuing as we are.", user);
312 }
313 else info("Successfully became user '%s'.", user);
src/dictionary.c
+7 -5
@@ -211,14 +211,16 @@ void *dictionary_set(DICTIONARY *dict, const char *name, void *value, size_t val
211 else {
212 debug(D_REGISTRY, "Dictionary: cloning value to '%s'", name);
213
214 - void *value = malloc(value_len),
214 + // copy the new value without breaking
215 + // any other thread accessing the same entry
216 + void *new = malloc(value_len),
217 *old = nv->value;
218
217 - if(unlikely(!nv->value))
219 + if(unlikely(!new))
220 fatal("Cannot allocate value of size %zu", value_len);
221
220 - memcpy(value, value, value_len);
221 - nv->value = value;
222 + memcpy(new, value, value_len);
223 + nv->value = new;
224
225 debug(D_REGISTRY, "Dictionary: freeing old value of '%s'", name);
226 free(old);
@@ -289,7 +291,7 @@ static int dictionary_walker(avl *a, int (*callback)(void *entry, void *data), v
291 total += ret;
292
293 if(a->left) {
292 - dictionary_walker(a->left, callback, data);
294 + ret = dictionary_walker(a->left, callback, data);
295 if (ret < 0) return ret;
296 total += ret;
297 }
src/procfile.c
+1 -1
@@ -170,7 +170,7 @@ procfile *procfile_parser(procfile *ff) {
170 while(likely(s < e)) {
171 // we are not at the end
172
173 - switch(ff->separators[(int)(*s)]) {
173 + switch(ff->separators[(uint8_t)(*s)]) {
174 case PF_CHAR_IS_OPEN:
175 if(s == t) {
176 opened++;
src/registry.c
+2
@@ -819,6 +819,8 @@ int registry_log_load(void) {
819 break;
820 }
821 }
822 +
823 + fclose(fp);
824 }
825
826 // open the log again
src/rrd2json.c
+1 -2
@@ -628,8 +628,7 @@ void rrdr_json_wrapper_begin(RRDR *r, BUFFER *wb, uint32_t format, uint32_t opti
628
629 void rrdr_json_wrapper_end(RRDR *r, BUFFER *wb, uint32_t format, uint32_t options, int string_value)
630 {
631 - if(r) {;}
632 - if(format) {;}
631 + (void)format;
632
633 char kq[2] = "", // key quote
634 sq[2] = ""; // string quote
src/web_buffer.c
+1 -1
@@ -314,7 +314,7 @@ void buffer_free(BUFFER *b)
314
315 debug(D_WEB_BUFFER, "Freeing web buffer of size %zu.", b->size);
316
317 - if(b->buffer) free(b->buffer);
317 + free(b->buffer);
318 free(b);
319 }
320
src/web_client.c
+6 -2
@@ -121,7 +121,7 @@ struct web_client *web_client_create(int listener)
121
122 case AF_INET6:
123 if(strncmp(w->client_ip, "::ffff:", 7) == 0) {
124 - strcpy(w->client_ip, &w->client_ip[7]);
124 + memmove(w->client_ip, &w->client_ip[7], strlen(&w->client_ip[7]) + 1);
125 debug(D_WEB_CLIENT_ACCESS, "%llu: New IPv4 web client from %s port %s on socket %d.", w->id, w->client_ip, w->client_port, w->ifd);
126 }
127 else
@@ -778,6 +778,9 @@ int web_client_api_v1_badge(struct web_client *w, char *url) {
778 int points = (points_str && *points_str )?atoi(points_str):1;
779 int precision = (precision_str && *precision_str)?atoi(precision_str):-1;
780
781 + if(!multiply) multiply = 1;
782 + if(!divide) divide = 1;
783 +
784 int refresh = 0;
785 if(refresh_str && *refresh_str) {
786 if(!strcmp(refresh_str, "auto")) {
@@ -1316,9 +1319,10 @@ int web_client_api_old_data_request(struct web_client *w, char *url, int datasou
1319
1320 // get the name of the data to show
1321 char *tok = mystrsep(&url, "/");
1322 + if(!tok) tok = "";
1323
1324 // do we have such a data set?
1321 - if(tok && *tok) {
1325 + if(*tok) {
1326 debug(D_WEB_CLIENT, "%llu: Searching for RRD data with name '%s'.", w->id, tok);
1327 st = rrdset_find_byname(tok);
1328 if(!st) st = rrdset_find(tok);
src/web_server.c
+4 -2
@@ -111,7 +111,8 @@ int create_listen_socket4(const char *ip, int port, int listen_backlog)
111 }
112
113 /* avoid "address already in use" */
114 - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void*)&sockopt, sizeof(sockopt));
114 + if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void*)&sockopt, sizeof(sockopt)) != 0)
115 + error("Cannot set SO_REUSEADDR on port's %d socket.", port);
116
117 struct sockaddr_in name;
118 memset(&name, 0, sizeof(struct sockaddr_in));
@@ -162,7 +163,8 @@ int create_listen_socket6(const char *ip, int port, int listen_backlog)
163 }
164
165 /* avoid "address already in use" */
165 - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void*)&sockopt, sizeof(sockopt));
166 + if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void*)&sockopt, sizeof(sockopt)) != 0)
167 + error("Cannot set SO_REUSEADDR on port's %d socket.", port);
168
169 struct sockaddr_in6 name;
170 memset(&name, 0, sizeof(struct sockaddr_in6));