shared/table: do not pass a NULL string to strdup() - #3980
Draft
mittal-ishaan wants to merge 2 commits into
Draft
Conversation
shr_table_set_value_str() passed @str straight to strdup(), so a NULL value crashed in strlen(). libnvme returns NULL for a blank sysfs attribute, so "nvme list" segfaults on a controller which reports an all-spaces firmware revision. Treat a NULL string as an empty string, leaving the cell blank. Signed-off-by: mittal-ishaan <ishaanmittal123@gmail.com>
mittal-ishaan
marked this pull request as draft
September 3, 2026 22:56
mittal-ishaan
force-pushed
the
fix-table-null-string
branch
from
September 3, 2026 22:57
c295adb to
8ad2bd7
Compare
Check that a NULL string is stored as an empty string and that the table still prints. Without the previous patch the test segfaults. Signed-off-by: mittal-ishaan <ishaanmittal123@gmail.com>
mittal-ishaan
force-pushed
the
fix-table-null-string
branch
from
September 3, 2026 23:01
8ad2bd7 to
ee5ea19
Compare
Collaborator
|
I am not against making the table code more robust, that's fine. Though we could just do the right thing with the defaults, that means instead of libnvme_ctrl_get_firmware(n->c, &val, NULL);do a libnvme_ctrl_get_firmware(n->c, &val, ""); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
nvme listsegfaults when a controller reports a blank firmware revision.libnvme's
__nvme_get_attr()strips trailing blanks and returnsNULLwhen nothing is left, solibnvme_ns_get_firmware()returnsNULLfor such a controller.list_item()hands that toshr_table_set_value_str(), which callsstrdup(str)unguarded and dies instrlen().Seen on Ubuntu 26.04 (nvme-cli 2.16, libnvme 1.16.1), GCP node whose persistent disk (model
nvme_card-pd) has an all-spacesfirmware_rev:A
NULLstring is now stored as an empty string, so the cell stays blank. Returning-EINVALinstead would make the callers drop the whole device row. The same setter also feeds serial, model and controller address, which can beNULLfor the same reason.