Skip to content

Commit aeeab66

Browse files
udisks2: check for EINTR when reading in recover_key()
Also try to prevent possible overflows. Signed-off-by: Sergio Correia <[email protected]>
1 parent b1197ca commit aeeab66

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/luks/udisks2/clevis-luks-udisks2.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,12 @@ on_signal(int sig)
301301
safeclose(&pair[0]);
302302
}
303303

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

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

383383
bytes = 0;
384-
for (ssize_t block = 1; block > 0; bytes += block) {
385-
block = read(pull[PIPE_RD], &out[bytes], max - bytes);
386-
if (block < 0) {
384+
ssize_t block = 0;
385+
while (max > 0 && max > bytes) {
386+
do {
387+
block = read(pull[PIPE_RD], &out[bytes], max - bytes);
388+
} while (block < 0 && errno == EINTR);
389+
if (block < 0 || block < INT32_MIN || block > INT32_MAX) {
387390
kill(chld, SIGTERM);
388391
goto error;
389392
}
393+
if (block == 0)
394+
break;
395+
bytes += block;
390396
}
391397

392398
safeclose(&pull[PIPE_RD]);

0 commit comments

Comments
 (0)