Changeset View
Standalone View
usr.bin/uuencode/uuencode.c
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
/* | /* | ||||
* uuencode [input] output | * uuencode [input] output | ||||
* | * | ||||
* Encode a file so it can be mailed to a remote system. | * Encode a file so it can be mailed to a remote system. | ||||
*/ | */ | ||||
#include <sys/capsicum.h> | |||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/socket.h> | #include <sys/socket.h> | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <netinet/in.h> | #include <netinet/in.h> | ||||
#include <capsicum_helpers.h> | |||||
#include <err.h> | #include <err.h> | ||||
#include <libgen.h> | #include <libgen.h> | ||||
#include <resolv.h> | #include <resolv.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
static void encode(void); | static void encode(void); | ||||
static void base64_encode(void); | static void base64_encode(void); | ||||
static void usage(void); | static void usage(void); | ||||
static FILE *output; | static FILE *output; | ||||
static int mode; | static int mode; | ||||
static char raw = 0; | static char raw = 0; | ||||
static char **av; | static char **av; | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | #define RW (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) | ||||
} | } | ||||
av = argv; | av = argv; | ||||
if (outfile != NULL) { | if (outfile != NULL) { | ||||
output = fopen(outfile, "w+"); | output = fopen(outfile, "w+"); | ||||
if (output == NULL) | if (output == NULL) | ||||
err(1, "unable to open %s for output", outfile); | err(1, "unable to open %s for output", outfile); | ||||
cap_rights_t out_rights; | |||||
cem: style(9) asks for variable declarations to be placed at least top of scope, if not at the top… | |||||
cap_rights_init(&out_rights, CAP_FSTAT | CAP_WRITE | CAP_SEEK ); | |||||
cemUnsubmitted Done Inline ActionsIs this really all that is needed on output, or do we also need the usual stream rights? I'd suggest using caph_limit_stream(fileno(output), CAP_WRITE). cem: Is this really all that is needed on `output`, or do we also need the usual stream rights? I'd… | |||||
if (cap_rights_limit( output->_file, &out_rights )) | |||||
cemUnsubmitted Done Inline Actionsstyle(9) nit: excess spaces between parens Use fileno(3) to access output's fd; do not access FILE members directly. style(9) nit: Do not use non-boolean values directly in conditionals (i.e., compare cap_rights_limit(...) to zero). cem: style(9) nit: excess spaces between parens
Use `fileno(3)` to access `output`'s fd; do not… | |||||
err(1, "unable to limit rights for %s", outfile); | |||||
} else | } else | ||||
output = stdout; | output = stdout; | ||||
if (caph_limit_stdio() != 0) | |||||
errx(1, "Failed to limit stdio"); | |||||
if (cap_enter() < 0 && errno != ENOSYS) | |||||
cemUnsubmitted Not Done Inline ActionsThis could be replaced with caph_enter() :-). Are we sure this program does not need to cache catpages before entering the sandbox? (I.e., it does not attempt to access any localization after this point, if lang is not en_US?) cem: This could be replaced with `caph_enter()` :-).
Are we sure this program does not need to… | |||||
bkidney_briankidney.caAuthorUnsubmitted Not Done Inline ActionsI ran the modifier uuencode through ktrace(1) and found no reference to anything like localization after caph_enter(). The only system call observed wrt file descriptors were the read and write call for the input and output files. bkidney_briankidney.ca: I ran the modifier uuencode through `ktrace(1)` and found no reference to anything like… | |||||
err(1, "unable to enter capability mode"); | |||||
if (base64) | if (base64) | ||||
base64_encode(); | base64_encode(); | ||||
else | else | ||||
encode(); | encode(); | ||||
if (ferror(output)) | if (ferror(output)) | ||||
errx(1, "write error"); | errx(1, "write error"); | ||||
exit(0); | exit(0); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines |
style(9) asks for variable declarations to be placed at least top of scope, if not at the top of the function.