Skip to content

Conversation

@tcharding
Copy link
Contributor

@tcharding tcharding commented Oct 10, 2017

CID 147480: Logically dead code (DEADCODE)

Remove non-null check and subsequent function call. Add ASSERT to future
proof the code.

usage label is only jumped to before zhp is initialized.

CID 147584: Out-of-bounds access (OVERRUN)

Subtract length of current string from buffer length for size argument
to snprintf.

Starting address for the write is the start of the buffer + the current
string length. We need to subtract this string length else risk a buffer
overflow.

How Has This Been Tested?

Code is untested.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (a change to man pages or other documentation)

Checklist:

  • My code follows the ZFS on Linux code style requirements.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • All commit messages are properly formatted and contain Signed-off-by.
  • Change has been approved by a ZFS on Linux member.

cmd/zed/zed.c Outdated
/* Notify parent that daemonization is complete. */
zed_log_pipe_close_writes();

(void) close(devnull);
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't quite right. devnull will under normal conditions be larger than STDERR_FILENO so this will be closed on line 202. If that's somehow not that case then one of the dup2() call above must fail. So this actually looks like a false positive to me since Coverity probably doesn't understand the constraints on STD*_FILENO's. Plus adding the close here would result in devnull being closed twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @behlendorf. I'll try to be more careful. Thanks for you patience.

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like you forgot to drop this hunk from the patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ouch, I swear I was not being ironic in the comment above.

usage:
if (zhp)
zfs_close(zhp);
ASSERT(zhp != NULL);
Copy link
Contributor

Choose a reason for hiding this comment

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

You mean ASSERT3P(zhp, ==, NULL); here since zfs_open() must never have been called.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Next mistake on these macros and I owe you a beer.

@tcharding tcharding changed the title Fix coverity defects: 147480, 147584, 147624 Fix coverity defects: 147480, 147584 Oct 12, 2017
@codecov
Copy link

codecov bot commented Oct 12, 2017

Codecov Report

Merging #6745 into master will decrease coverage by 0.4%.
The diff coverage is 83.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6745      +/-   ##
==========================================
- Coverage   74.51%   74.11%   -0.41%     
==========================================
  Files         297      295       -2     
  Lines       94353    93884     -469     
==========================================
- Hits        70310    69580     -730     
- Misses      24043    24304     +261
Flag Coverage Δ
#kernel 74.32% <ø> (-0.04%) ⬇️
#user 63.49% <83.33%> (-3.28%) ⬇️
Impacted Files Coverage Δ
cmd/zed/zed.c 37.93% <0%> (-0.33%) ⬇️
cmd/zdb/zdb.c 61.49% <100%> (-0.43%) ⬇️
cmd/zfs/zfs_main.c 80.6% <100%> (+0.15%) ⬆️
module/icp/algs/skein/skein_port.h 0% <0%> (-100%) ⬇️
lib/libspl/include/sys/byteorder.h 42.85% <0%> (-57.15%) ⬇️
module/icp/algs/sha2/sha2.c 75.19% <0%> (-17.02%) ⬇️
module/zfs/zio_crypt.c 72.15% <0%> (-9.97%) ⬇️
module/icp/algs/modes/gcm.c 68.63% <0%> (-9.23%) ⬇️
module/icp/algs/aes/aes_impl.c 59.45% <0%> (-8.11%) ⬇️
module/icp/algs/modes/ccm.c 76.6% <0%> (-7.38%) ⬇️
... and 64 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c616dcf...f0297d2. Read the comment docs.

CID 147480: Logically dead code (DEADCODE)

Remove non-null check and subsequent function call. Add ASSERT to future
proof the code.

usage label is only jumped to before `zhp` is initialized.

CID 147584: Out-of-bounds access (OVERRUN)

Subtract length of current string from buffer length for `size` argument
to `snprintf`.

Starting address for the write is the start of the buffer + the current
string length. We need to subtract this string length else risk a buffer
overflow.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
@behlendorf behlendorf merged commit ced2819 into openzfs:master Oct 16, 2017
wli5 pushed a commit to wli5/zfs that referenced this pull request Oct 20, 2017
CID 147480: Logically dead code (DEADCODE)

Remove non-null check and subsequent function call. Add ASSERT to future
proof the code.

usage label is only jumped to before `zhp` is initialized.

CID 147584: Out-of-bounds access (OVERRUN)

Subtract length of current string from buffer length for `size` argument
to `snprintf`.

Starting address for the write is the start of the buffer + the current
string length. We need to subtract this string length else risk a buffer
overflow.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tobin C. Harding <me@tobin.cc>
Closes openzfs#6745
Nasf-Fan pushed a commit to Nasf-Fan/zfs that referenced this pull request Nov 4, 2017
CID 147480: Logically dead code (DEADCODE)

Remove non-null check and subsequent function call. Add ASSERT to future
proof the code.

usage label is only jumped to before `zhp` is initialized.

CID 147584: Out-of-bounds access (OVERRUN)

Subtract length of current string from buffer length for `size` argument
to `snprintf`.

Starting address for the write is the start of the buffer + the current
string length. We need to subtract this string length else risk a buffer
overflow.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tobin C. Harding <me@tobin.cc>
Closes openzfs#6745
Nasf-Fan pushed a commit to Nasf-Fan/zfs that referenced this pull request Nov 6, 2017
CID 147480: Logically dead code (DEADCODE)

Remove non-null check and subsequent function call. Add ASSERT to future
proof the code.

usage label is only jumped to before `zhp` is initialized.

CID 147584: Out-of-bounds access (OVERRUN)

Subtract length of current string from buffer length for `size` argument
to `snprintf`.

Starting address for the write is the start of the buffer + the current
string length. We need to subtract this string length else risk a buffer
overflow.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tobin C. Harding <me@tobin.cc>
Closes openzfs#6745
Nasf-Fan pushed a commit to Nasf-Fan/zfs that referenced this pull request Jan 29, 2018
CID 147480: Logically dead code (DEADCODE)

Remove non-null check and subsequent function call. Add ASSERT to future
proof the code.

usage label is only jumped to before `zhp` is initialized.

CID 147584: Out-of-bounds access (OVERRUN)

Subtract length of current string from buffer length for `size` argument
to `snprintf`.

Starting address for the write is the start of the buffer + the current
string length. We need to subtract this string length else risk a buffer
overflow.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tobin C. Harding <me@tobin.cc>
Closes openzfs#6745
Nasf-Fan pushed a commit to Nasf-Fan/zfs that referenced this pull request Feb 13, 2018
CID 147480: Logically dead code (DEADCODE)

Remove non-null check and subsequent function call. Add ASSERT to future
proof the code.

usage label is only jumped to before `zhp` is initialized.

CID 147584: Out-of-bounds access (OVERRUN)

Subtract length of current string from buffer length for `size` argument
to `snprintf`.

Starting address for the write is the start of the buffer + the current
string length. We need to subtract this string length else risk a buffer
overflow.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tobin C. Harding <me@tobin.cc>
Closes openzfs#6745
FransUrbo pushed a commit to FransUrbo/zfs that referenced this pull request Apr 28, 2019
CID 147480: Logically dead code (DEADCODE)

Remove non-null check and subsequent function call. Add ASSERT to future
proof the code.

usage label is only jumped to before `zhp` is initialized.

CID 147584: Out-of-bounds access (OVERRUN)

Subtract length of current string from buffer length for `size` argument
to `snprintf`.

Starting address for the write is the start of the buffer + the current
string length. We need to subtract this string length else risk a buffer
overflow.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tobin C. Harding <me@tobin.cc>
Closes openzfs#6745
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants