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

kbootd: fix overflow when reading gpt header #13

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions kbootd/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ static bool prompt_stop_boot(void)

static void set_terminal_single_char_read(void)
{
struct termios local_term_attributes;
struct termios local_term_attributes;

if (!isatty(STDIN_FILENO))
return;
if (tcgetattr(STDIN_FILENO, &local_term_attributes))
return;
if (!isatty(STDIN_FILENO))
return;
if (tcgetattr(STDIN_FILENO, &local_term_attributes))
return;

local_term_attributes.c_lflag &= ~(ICANON | ECHO);
local_term_attributes.c_cc[VMIN] = 1;
local_term_attributes.c_cc[VTIME] = 0;
tcsetattr(STDIN_FILENO, TCSANOW, &local_term_attributes);
local_term_attributes.c_lflag &= ~(ICANON | ECHO);
local_term_attributes.c_cc[VMIN] = 1;
local_term_attributes.c_cc[VTIME] = 0;
tcsetattr(STDIN_FILENO, TCSANOW, &local_term_attributes);
}

static bool stop_boot(void)
Expand All @@ -91,7 +91,7 @@ static bool stop_boot(void)
return stop;
}

set_terminal_single_char_read();
set_terminal_single_char_read();

stop = prompt_stop_boot();
if (stop)
Expand Down
9 changes: 6 additions & 3 deletions kbootd/src/part.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ static void gpt_convert_efi_name_to_char(char *s, void *es, int n)
static int find_gpt_entry(int fd, const char *name, struct gpt_entry *gpt_e,
off_t *offset)
{
struct gpt_header gpt_hdr;
struct gpt_header *gpt_hdr;
char part[PARTNAME_SZ];
char data[LBA_SIZE];
int ret;
Expand All @@ -339,13 +339,16 @@ static int find_gpt_entry(int fd, const char *name, struct gpt_entry *gpt_e,
return ret;
}

ret = kread(fd, (char *)&gpt_hdr, LBA_SIZE);
memset(data, '\0', LBA_SIZE);
ret = kread(fd, data, LBA_SIZE);
if (ret == -1) {
log("read GPT header failed\n");
return -1;
}
gpt_hdr = (struct gpt_header *)data;

for (int i = 0; i < gpt_hdr.n_parts; i++) {
for (int i = 0; i < gpt_hdr->n_parts; i++) {
memset(data, '\0', LBA_SIZE);
ret = kread(fd, data, LBA_SIZE);
if (ret == -1) {
log("read GPT entry failed\n");
Expand Down