-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gnrc: fix several issues found with LLVM's static code analyzer #10350
Conversation
@@ -240,7 +240,7 @@ int gnrc_ipv6_nib_get_next_hop_l2addr(const ipv6_addr_t *dst, | |||
gnrc_netif_acquire(netif); | |||
} | |||
node = _nib_onl_get(&route.next_hop, | |||
(netif == NULL) ? netif->pid : 0); | |||
(netif != NULL) ? netif->pid : 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was an actual bug waiting to happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we were lucky (or rather unlucky) that this line never really was hit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not have time to review before the week end.
But for the two real bug fixes in nib.c
and nib_pl.c
files, I agree with the changes (only reviewed not tested).
@@ -517,6 +517,9 @@ static inline uint32_t _exp_backoff_retrans_timer(uint8_t ns_sent, | |||
uint32_t tmp = random_uint32_range(NDP_MIN_RANDOM_FACTOR, | |||
NDP_MAX_RANDOM_FACTOR); | |||
|
|||
/* this is a given since ns_sent is only incremented in _probe_nbr when | |||
* it is less than (NDP_MAX_NS_NUMOF + 2) */ | |||
assert(ns_sent < 32); | |||
/* backoff according to https://tools.ietf.org/html/rfc7048 with | |||
* BACKOFF_MULTIPLE == 2 */ | |||
tmp = ((1 << ns_sent) * retrans_timer * tmp) / US_PER_MS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For 16bit/8bit platforms, should not this 1
also be a uint32_t
or even uint64_t
as NDP_MAX_NS_NUMOF
can be 17
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be wrong, but this sounds like a separate issue not directly related to this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For 16bit/8bit platforms, should not this
1
also be auint32_t
or evenuint64_t
asNDP_MAX_NS_NUMOF
can be17
?
Huh, I don't get your statement... tmp
is an uint32_t
. 17 + 2 is on all platforms < 32.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or do you mean, the 1
should actually be 1UL
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(if it is the latter I agree with @bergzand: this is a matter of a separate PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bergzand it is not related to silencing scan-build
but has been revealed by running the static analyzer. And unfortunately we do not have llvm
support with 8/16bit platforms.
If it is silenced, it would be forgotten.
@miri64 yes I meant the 1
should be converted to an uint32
, not sure of the size of 1UL
in our 8 and 16bit platform and in general ((1 << ns_sent) * retrans_timer * tmp)
should not overflow in its type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cladmi things can be fixed in a separate PR while this PR is open ;-) and thus not be forgotten. Since I now understand your remark better, I will do that as soon as I have a keyboard under my fingers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the issue with newlines in the shell command. |
See #10358 for the release critical parts |
eb8cd95
to
6e89c62
Compare
Rebased to current master and removed commits already merged with #10358. |
6e89c62
to
331d3e3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebased to current master
@@ -382,7 +382,7 @@ static gnrc_pktsnip_t *_create_snip(gnrc_pktsnip_t *next, const void *data, size | |||
} | |||
} | |||
_set_pktsnip(pkt, next, _data, size, type); | |||
if (data != NULL) { | |||
if ((data != NULL) && (size > 0)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was fixed in #10786 as well.
I wanted to see what are the remaining PR that needs a backport and found this one. It's opened for quite some time now, so what's the status ? Should it be backported to 2019.01-branch ? |
There was some unrelated discussion in #10350 (comment) which was then fixed in #10369 (which was also never merged), other than that I believe this PR is ready to |
@cladmi, since you already started to review this, would you mind to have a second look/test and eventually give an ACK ? |
331d3e3
to
b443a6b
Compare
Rebased to current master to resolve conflicts. |
I piggy-backed some cppcheck suppressions for warnings that Travis were complaining about. |
Postponed and removed the 'needs backport' label. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes looks good, but it looks like the one for the command line handling could be changing the output. Is there a way to test this ?
@@ -379,19 +378,16 @@ static void _netif_list_ipv6(ipv6_addr_t *addr, uint8_t flags) | |||
break; | |||
} | |||
} | |||
line_thresh = _newline(0U, line_thresh); | |||
puts(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These seems they would change the output, as the previous version looks like its printing \n (many spaces)
.
Not sure if it is wanted to replace it with only \n
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same goes here.
if ((ipv6_addr_is_multicast(addr))) { | ||
char addr_str[IPV6_ADDR_MAX_STR_LEN]; | ||
ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)); | ||
printf("inet6 group: %s", addr_str); | ||
printf("inet6 group: %s\n", addr_str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes from always printing \n (many spaces)
to sometime only printing a new line.
Not sure if it is wanted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well the line is always too long and int should be broken after one group in any case.
Compile and run |
The variable is without usage reassigned with `dodag->parent` below.
For the source address compression it was already done the same way in 12bcc46
0a5bb10
to
3ee75c3
Compare
Rebased and ping??!? Bug fixes. Mini, tiny low-hanging fruit bug-fixes, that want merging! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
next time better keep simple assert additions seperate please!
Please clarify. |
Ah, I looked at the diff, and saw some new "asserts()". Those I'd probably ACK very fast. |
Ok, so you meant separate PR, because I was confused, since the assertion fixes are in separate commits. |
The indentation of `ifconfig` is currently broken, due to an attempt to fix some `scan-build` errors.
…sion shell_commands: fix regression to ifconfig introduced in #10350
The indentation of `ifconfig` is currently broken, due to an attempt to fix some `scan-build` errors.
Contribution description
Fixes a few issues that were found when checking
gnrc_networking
with LLVM's static code analyzer.Testing procedure
Execute
make -C examples/gnrc_networking scan-build
. It should pass. For functionality tests I recommend to use the a subset of the tests outlined in the release specifications.Issues/PRs references
None