Changeset View
Changeset View
Standalone View
Standalone View
sbin/dumpon/dumpon.c
Show First 20 Lines • Show All 326 Lines • ▼ Show 20 Lines | case -1: | ||||
break; | break; | ||||
case 0: | case 0: | ||||
close(filedes[0]); | close(filedes[0]); | ||||
_genkey(pubkeyfile, kdap); | _genkey(pubkeyfile, kdap); | ||||
/* Write the new kdap back to the parent. */ | /* Write the new kdap back to the parent. */ | ||||
bytes = write(filedes[1], kdap, sizeof(*kdap)); | bytes = write(filedes[1], kdap, sizeof(*kdap)); | ||||
if (bytes != sizeof(*kdap)) | if (bytes != sizeof(*kdap)) | ||||
err(1, "genkey pipe write"); | err(1, "genkey pipe write"); | ||||
bytes = write(filedes[1], kdap->kda_encryptedkey, | |||||
kdap->kda_encryptedkeysize); | |||||
if (bytes != kdap->kda_encryptedkeysize) | |||||
err(1, "genkey pipe write kda_encryptedkey"); | |||||
_exit(0); | _exit(0); | ||||
} | } | ||||
close(filedes[1]); | close(filedes[1]); | ||||
/* Read in the child's genkey() result into kdap. */ | /* Read in the child's genkey() result into kdap. */ | ||||
bytes = read(filedes[0], kdap, sizeof(*kdap)); | bytes = read(filedes[0], kdap, sizeof(*kdap)); | ||||
if (bytes != sizeof(*kdap)) | if (bytes != sizeof(*kdap)) | ||||
errx(1, "genkey pipe read"); | errx(1, "genkey pipe read"); | ||||
if (kdap->kda_encryptedkeysize > KERNELDUMP_ENCKEY_MAX_SIZE) | |||||
markj: We should check the length passed by the child against KERNELDUMP_ENCKEY_MAX_SIZE, rather than… | |||||
errx(1, "Public key has to be at most %db long.", | |||||
8 * KERNELDUMP_ENCKEY_MAX_SIZE); | |||||
kdap->kda_encryptedkey = calloc(1, kdap->kda_encryptedkeysize); | |||||
if (kdap->kda_encryptedkey == NULL) | |||||
err(1, "Unable to allocate encrypted key"); | |||||
bytes = read(filedes[0], kdap->kda_encryptedkey, | |||||
kdap->kda_encryptedkeysize); | |||||
if (bytes != kdap->kda_encryptedkeysize) | |||||
errx(1, "genkey pipe read kda_encryptedkey"); | |||||
error = waitpid(pid, &status, WEXITED); | error = waitpid(pid, &status, WEXITED); | ||||
if (error == -1) | if (error == -1) | ||||
err(1, "waitpid"); | err(1, "waitpid"); | ||||
if (WIFEXITED(status) && WEXITSTATUS(status) != 0) | if (WIFEXITED(status) && WEXITSTATUS(status) != 0) | ||||
errx(1, "genkey child exited with status %d", | errx(1, "genkey child exited with status %d", | ||||
WEXITSTATUS(status)); | WEXITSTATUS(status)); | ||||
else if (WIFSIGNALED(status)) | else if (WIFSIGNALED(status)) | ||||
errx(1, "genkey child exited with signal %d", | errx(1, "genkey child exited with signal %d", | ||||
▲ Show 20 Lines • Show All 315 Lines • Show Last 20 Lines |
We should check the length passed by the child against KERNELDUMP_ENCKEY_MAX_SIZE, rather than blindly allocating the amount specified.