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

gpt-auto-generator: Ignore zero sized block devices #26904

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/gpt-auto-generator/gpt-auto-generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,8 @@ static int enumerate_partitions(dev_t devnum) {
_cleanup_(dissected_image_unrefp) DissectedImage *m = NULL;
_cleanup_(loop_device_unrefp) LoopDevice *loop = NULL;
_cleanup_free_ char *devname = NULL;
char p[SYS_BLOCK_PATH_MAX("/size")];
char *s = NULL;
int r, k;

r = block_get_whole_disk(devnum, &devnum);
Expand All @@ -742,6 +744,13 @@ static int enumerate_partitions(dev_t devnum) {
if (r < 0)
return log_debug_errno(r, "Failed to open %s: %m", devname);

xsprintf_sys_block_path(p, "/size", devnum);
r = read_one_line_file(p, &s);
if (r == 0 && !strcmp(s, "0")) {
Comment on lines +748 to +749
Copy link
Member

Choose a reason for hiding this comment

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

read_one_line_file() returns the number of characters read. If the file is empty, this will be 0. The conditional, as written, cannot be true.

Did this get tested at all?

log_debug_errno(r, "Zero sized block device %s, ignoring.", devname);
return 0;
}

r = dissect_loop_device(
loop,
NULL, NULL,
Expand Down