From 1378138b26dab02240487324dbb4bdc54869fc48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Wed, 11 May 2016 20:20:20 +0200 Subject: [PATCH 1/3] Med: make foreach_* macros use variable refs passed as arguments ...instead of accidentally stealing variables from the outter, lexical scope, which only worked thanks to match on identifiers, and would get ultimately broken on renaming them in respective lexical scopes. --- src/ticket.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ticket.h b/src/ticket.h index d4a77c5f..abd45b3e 100644 --- a/src/ticket.h +++ b/src/ticket.h @@ -35,8 +35,8 @@ extern int TIME_RES; #define DEFAULT_RETRIES 10 -#define foreach_ticket(i_,t_) for(i=0; (t_=booth_conf->ticket+i, iticket_count); i++) -#define foreach_node(i_,n_) for(i=0; (n_=booth_conf->site+i, isite_count); i++) +#define foreach_ticket(i_,t_) for(i_=0; (t_=booth_conf->ticket+i_, i_ticket_count); i_++) +#define foreach_node(i_,n_) for(i_=0; (n_=booth_conf->site+i_, i_site_count); i_++) #define set_leader(tk, who) do { \ tk->leader = who; \ From fd90d7cf7548eef8f519ad57399ee2bae813e6a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Thu, 12 May 2016 18:11:25 +0200 Subject: [PATCH 2/3] Med: format_peers: fix a memleak in case of buffer too small Note that such a case seems impossible but there may be other issues that will add up (see, e.g., reckless snprintf use pointed out with https://github.com/ClusterLabs/pacemaker/pull/810, something should eventually be reflected here as well). Discovered-by: static analysis/Coverity --- src/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index c23c1218..9f52064f 100644 --- a/src/main.c +++ b/src/main.c @@ -242,8 +242,10 @@ static int format_peers(char **pdata, unsigned int *len) s->recv_err_cnt, s->sec_cnt, s->invalid_cnt); - if (alloc - (cp - data) <= 0) + if (alloc - (cp - data) <= 0) { + free(data); return -ENOMEM; + } } *pdata = data; From c49d83c2d0b747a435ef675f64841d2532e06896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Fri, 13 May 2016 17:34:15 +0200 Subject: [PATCH 3/3] Med: get_local_id: denoopize dependent condition (signedness issue) Otherwise, condition in booth_tcp_init (src/transport.c): if (get_local_id() < 0) return -1; could never be triggered. It should not be triggered anyway at the current state, but try to stay sane no matter what, especially if the issue was hidden in such a nasty way. Also note that using "int" should be pretty much fine as precautions are taken in add_site so as to keep MSB unset for site IDs in use, which is sufficient to distinguish them from a signalling negative value. Discovered-by: static analysis/Coverity --- src/inline-fn.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inline-fn.h b/src/inline-fn.h index b36facd5..db1c9385 100644 --- a/src/inline-fn.h +++ b/src/inline-fn.h @@ -29,7 +29,7 @@ -inline static uint32_t get_local_id(void) +inline static int get_local_id(void) { return local ? local->site_id : -1; }