Skip to content
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

Merged
merged 4 commits into from
Jun 20, 2019

Conversation

miri64
Copy link
Member

@miri64 miri64 commented Nov 8, 2018

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

@miri64 miri64 added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch labels Nov 8, 2018
@miri64 miri64 added this to the Release 2018.10 milestone Nov 8, 2018
@miri64 miri64 requested review from cladmi and bergzand November 8, 2018 14:00
@@ -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);
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Contributor

@cladmi cladmi left a 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;
Copy link
Contributor

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 ?

Copy link
Member

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.

Copy link
Member Author

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 ?

Huh, I don't get your statement... tmp is an uint32_t. 17 + 2 is on all platforms < 32.

Copy link
Member Author

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?

Copy link
Member Author

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)

Copy link
Contributor

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 llvmsupport 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.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miri64
Copy link
Member Author

miri64 commented Nov 8, 2018

Fixed the issue with newlines in the shell command.

@miri64
Copy link
Member Author

miri64 commented Nov 9, 2018

See #10358 for the release critical parts

@miri64
Copy link
Member Author

miri64 commented Nov 9, 2018

Rebased to current master and removed commits already merged with #10358.

Copy link
Member Author

@miri64 miri64 left a 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)) {
Copy link
Member Author

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.

@miri64 miri64 added the Community: Hack'n'ACK candidate This PR is a candidate for review and discussion during one of RIOT's monthly Hack'n'ACK parties label Jan 29, 2019
@aabadie
Copy link
Contributor

aabadie commented Feb 12, 2019

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 ?

@miri64
Copy link
Member Author

miri64 commented Feb 12, 2019

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 be merged be reviewed.

@aabadie
Copy link
Contributor

aabadie commented Feb 12, 2019

@cladmi, since you already started to review this, would you mind to have a second look/test and eventually give an ACK ?

@miri64
Copy link
Member Author

miri64 commented Feb 12, 2019

Rebased to current master to resolve conflicts.

@miri64
Copy link
Member Author

miri64 commented Feb 12, 2019

I piggy-backed some cppcheck suppressions for warnings that Travis were complaining about.

@aabadie
Copy link
Contributor

aabadie commented Feb 13, 2019

After looking at it again, it seems that this PR only contains minor things. I propose that we postpone it and remove the "needs backport" label. @miri64, @cladmi, what do you think ?

@aabadie aabadie removed the Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch label Feb 13, 2019
@aabadie
Copy link
Contributor

aabadie commented Feb 13, 2019

Postponed and removed the 'needs backport' label.

Copy link
Contributor

@cladmi cladmi left a 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("");
Copy link
Contributor

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.

Copy link
Member Author

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);
Copy link
Contributor

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.

Copy link
Member Author

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.

@miri64
Copy link
Member Author

miri64 commented Mar 26, 2019

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 ?

Compile and run gnrc_networking and check if the output changed for ifconfig ;-)

@miri64 miri64 force-pushed the gnrc/fix/static-analyzis branch from 0a5bb10 to 3ee75c3 Compare June 20, 2019 14:23
@miri64
Copy link
Member Author

miri64 commented Jun 20, 2019

Rebased and ping??!? Bug fixes. Mini, tiny low-hanging fruit bug-fixes, that want merging!

@kaspar030 kaspar030 added the CI: run tests If set, CI server will run tests on hardware for the labeled PR label Jun 20, 2019
Copy link
Contributor

@kaspar030 kaspar030 left a 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!

@miri64
Copy link
Member Author

miri64 commented Jun 20, 2019

next time better keep simple assert additions seperate please!

Please clarify.

@kaspar030
Copy link
Contributor

Please clarify.

Ah, I looked at the diff, and saw some new "asserts()". Those I'd probably ACK very fast.
Changes to the output, not initializing some variables need deeper looking. So that would've been candidates for a differrent PR.

@miri64
Copy link
Member Author

miri64 commented Jun 20, 2019

Ok, so you meant separate PR, because I was confused, since the assertion fixes are in separate commits.

@miri64 miri64 merged commit d47ac80 into RIOT-OS:master Jun 20, 2019
@miri64 miri64 deleted the gnrc/fix/static-analyzis branch June 20, 2019 14:53
miri64 added a commit to miri64/RIOT that referenced this pull request Jun 26, 2019
The indentation of `ifconfig` is currently broken, due to an attempt to
fix some `scan-build` errors.
cladmi added a commit that referenced this pull request Jun 26, 2019
…sion

shell_commands: fix regression to ifconfig introduced in #10350
fjmolinas pushed a commit to fjmolinas/RIOT that referenced this pull request Aug 4, 2019
The indentation of `ifconfig` is currently broken, due to an attempt to
fix some `scan-build` errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR Community: Hack'n'ACK candidate This PR is a candidate for review and discussion during one of RIOT's monthly Hack'n'ACK parties Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants