summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorRasmus Villemoes <[email protected]>2025-11-10 21:54:10 +0100
committerTom Rini <[email protected]>2025-11-18 12:51:09 -0600
commit3c2a9475334ae32997b3bce8d24b39c8ffa9fc67 (patch)
tree18310f8b652e37270d520c6a88b5ac1b6b2f5d49 /cmd
parent365a7079fb918643da0f0709660a7d8ea76dd6f3 (diff)
disk/part.c: ensure strings in struct disk_partition are valid after successful get_info
Not all ->get_info implementations necessarily populate all the string members of struct disk_partition. Currently, only part_get_info_by_type() (and thereby part_get_info) ensure that the uuid strings are initialized; part_get_info_by_type() and part_get_info_by_uuid() do not. In fact, the latter could lead to a false positive match - if the ->get_info backend does not populate info->uuid, stale contents in info could cause the strncasecmp() to succeed. None of the functions currently ensure that the ->name and ->type strings are initialized. Instead of forcing all callers of any of these functions to pre-initialize info, or all implementations of the ->get_info method to ensure there are valid C strings in all four fields, create a small helper function and factor all invocations of ->get_info through that. This also consolidates the -ENOSYS check and standardizes on using log_debug() for reporting absence, instead of the current mix of PRINTF and log_debug(). It does mean we have to special-case -ENOSYS in the error cases inside the loops in the _by_uuid() and _by_name() functions, but it's still a net win in #LOC. Acked-by: Quentin Schulz <[email protected]> Signed-off-by: Rasmus Villemoes <[email protected]> Tested-by: Anshul Dalal <[email protected]>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gpt.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/cmd/gpt.c b/cmd/gpt.c
index e18e5036a06..84221881c39 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -724,7 +724,7 @@ static int gpt_enumerate(struct blk_desc *desc)
continue;
for (i = 1; i < part_drv->max_entries; i++) {
- ret = part_drv->get_info(desc, i, &pinfo);
+ ret = part_driver_get_info(part_drv, desc, i, &pinfo);
if (ret)
continue;
@@ -820,7 +820,7 @@ static int gpt_setenv(struct blk_desc *desc, const char *name)
int i;
for (i = 1; i < part_drv->max_entries; i++) {
- ret = part_drv->get_info(desc, i, &pinfo);
+ ret = part_driver_get_info(part_drv, desc, i, &pinfo);
if (ret)
continue;