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

fix reported defect from coverity scan #1706

Merged
merged 1 commit into from
Jan 25, 2024
Merged

Conversation

ankit-sam
Copy link
Contributor

Fix the two Null pointer dereferences issue reported by Coverity scan

Null pointer dereferences (FORWARD_NULL)
Dereferencing null pointer "l->td"

Null pointer dereferences (REVERSE_INULL)
Null-checking "p->td" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.

@@ -862,7 +862,7 @@ void setup_log(struct io_log **log, struct log_params *p,
l->log_ddir_mask = LOG_OFFSET_SAMPLE_BIT;
if (l->log_prio)
l->log_ddir_mask |= LOG_PRIO_SAMPLE_BIT;
if (l->td->o.log_max == IO_LOG_SAMPLE_BOTH)
if (l->td && l->td->o.log_max == IO_LOG_SAMPLE_BOTH)
Copy link
Owner

Choose a reason for hiding this comment

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

This is a work-around just to appease the checker, not a huge fan. Either p->td is always valid, and in which case l->td is also always valid, or it's valid to call setup_log() with NULL p->td and checking is needed. Decide which one it is and do the fix based on that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes setup_log() gets called with NULL p->td for agg-read_bw.log, agg-write_bw.log and agg-trim_bw.log. So this check is required.

I think this is the reason we have the same check few lines above.
if (l->td && l->td->o.io_submit_mode != IO_MODE_OFFLOAD)

Copy link
Owner

Choose a reason for hiding this comment

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

Gotcha - then the fix looks fine to me. Can you add a comment as to when it's NULL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, please take a look.

Copy link
Owner

Choose a reason for hiding this comment

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

Did you push it? Don't see it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah my mistake, I only updated the commit message previously. Its should be done now.

@ankit-sam ankit-sam force-pushed the coverity-fix branch 2 times, most recently from 6c26fa1 to acc481b Compare January 25, 2024 17:12
@axboe
Copy link
Owner

axboe commented Jan 25, 2024

Thanks!

@axboe axboe merged commit 90a0fbc into axboe:master Jan 25, 2024
10 checks passed
Fix the two Null pointer dereferences issue reported by Coverity scan

Null pointer dereferences  (FORWARD_NULL)
Dereferencing null pointer "l->td"

Null pointer dereferences  (REVERSE_INULL)
Null-checking "p->td" suggests that it may be null, but it has already
been dereferenced on all paths leading to the check.

For aggregate read, write and trim bandwidth log, the setup_log function
gets called with NULL pointer reference for thread data. Thus before
dereferencing further we should check "l->td".

Signed-off-by: Ankit Kumar <[email protected]>
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