Skip to content

log: Allow nvme_msg usage with invalid root pointer#246

Merged
igaw merged 1 commit intolinux-nvme:masterfrom
igaw:fix-nvme_msg
Feb 21, 2022
Merged

log: Allow nvme_msg usage with invalid root pointer#246
igaw merged 1 commit intolinux-nvme:masterfrom
igaw:fix-nvme_msg

Conversation

@igaw
Copy link
Copy Markdown
Collaborator

@igaw igaw commented Feb 17, 2022

24ac082 ("Add 'nvme_root_t' argument to nvme_msg()") and
19b1283 ("Move global logging variables into nvme_root_t") moved
the logging controller knobs into the root object. In case the pointer
is invalid we should not try to use it. Instead just bailing out just
log the line.

Signed-off-by: Daniel Wagner dwagner@suse.de

Fixes: #244

Copy link
Copy Markdown
Contributor

@martin-belanger martin-belanger left a comment

Choose a reason for hiding this comment

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

r also needs to be checked at lines 72-73

@igaw
Copy link
Copy Markdown
Collaborator Author

igaw commented Feb 18, 2022

This time even tested. Should work :)

Comment thread src/nvme/log.c Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't we test that the message is at the right level at the beginning of the function and return right away if we're not going to print it? This would avoid performing a whole lot of operations for nothing.

In other words:

/* Check if message is at the right level. If not, get out immediately */
if (r && lvl > r->log_level)  
    return;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good point. I'll update it accordingly :)

24ac082 ("Add 'nvme_root_t' argument to nvme_msg()") and
19b1283 ("Move global logging variables into nvme_root_t") moved
the logging controller knobs into the root object. In case the pointer
is invalid we should not try to use it. Instead just bailing out just
log the line.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
@igaw
Copy link
Copy Markdown
Collaborator Author

igaw commented Feb 21, 2022

I've also reformatted to code slightly, so it's easier to read (at least in my opinion :))

@igaw igaw merged commit 1254f58 into linux-nvme:master Feb 21, 2022
@igaw igaw deleted the fix-nvme_msg branch February 21, 2022 10:54
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.

__nvme_msg() is not checking for NULL before dereferencing pointer

3 participants