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

udisks2: misc fixes #464

Merged
merged 2 commits into from
May 9, 2024
Merged
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
24 changes: 16 additions & 8 deletions src/luks/udisks2/clevis-luks-udisks2.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ child_main(int sock)

error:
g_list_free_full(ctx.lst, g_free);
sarroutbi marked this conversation as resolved.
Show resolved Hide resolved
g_main_loop_unref(ctx.loop);
g_object_unref(ctx.clt);
if (ctx.loop)
g_main_loop_unref(ctx.loop);
if (ctx.clt)
g_object_unref(ctx.clt);
close(sock);
return exit_status;
}
Expand Down Expand Up @@ -299,12 +301,12 @@ on_signal(int sig)
safeclose(&pair[0]);
}

static ssize_t
recover_key(const pkt_t *jwe, char *out, size_t max, uid_t uid, gid_t gid)
static uint32_t
recover_key(const pkt_t *jwe, char *out, int32_t max, uid_t uid, gid_t gid)
{
int push[2] = { -1, -1 };
int pull[2] = { -1, -1 };
ssize_t bytes = 0;
int32_t bytes = 0;
pid_t chld = 0;

if (pipe(push) != 0)
Expand Down Expand Up @@ -379,12 +381,18 @@ recover_key(const pkt_t *jwe, char *out, size_t max, uid_t uid, gid_t gid)
}

bytes = 0;
for (ssize_t block = 1; block > 0; bytes += block) {
block = read(pull[PIPE_RD], &out[bytes], max - bytes);
if (block < 0) {
ssize_t block = 0;
while (max > 0 && max > bytes) {
do {
block = read(pull[PIPE_RD], &out[bytes], max - bytes);
} while (block < 0 && errno == EINTR);
if (block < 0 || block < INT32_MIN || block > INT32_MAX) {
kill(chld, SIGTERM);
goto error;
}
if (block == 0)
break;
bytes += block;
}

safeclose(&pull[PIPE_RD]);
Expand Down