Index: head/usr.bin/ministat/ministat.c =================================================================== --- head/usr.bin/ministat/ministat.c +++ head/usr.bin/ministat/ministat.c @@ -11,16 +11,20 @@ #include __FBSDID("$FreeBSD$"); -#include -#include +#include +#include +#include +#include + +#include #include #include -#include +#include +#include +#include #include +#include #include -#include -#include -#include #define NSTUDENT 100 #define NCONF 6 @@ -455,26 +459,14 @@ } static struct dataset * -ReadSet(const char *n, int column, const char *delim) +ReadSet(FILE *f, const char *n, int column, const char *delim) { - FILE *f; char buf[BUFSIZ], *p, *t; struct dataset *s; double d; int line; int i; - if (n == NULL) { - f = stdin; - n = ""; - } else if (!strcmp(n, "-")) { - f = stdin; - n = ""; - } else { - f = fopen(n, "r"); - } - if (f == NULL) - err(1, "Cannot open %s", n); s = NewSet(); s->name = strdup(n); line = 0; @@ -499,7 +491,6 @@ if (*buf != '\0') AddPoint(s, d); } - fclose(f); if (s->n < 3) { fprintf(stderr, "Dataset %s must contain at least 3 data points\n", n); @@ -536,7 +527,9 @@ int main(int argc, char **argv) { - struct dataset *ds[7]; + const char *setfilenames[MAX_DS - 1]; + struct dataset *ds[MAX_DS - 1]; + FILE *setfiles[MAX_DS - 1]; int nds; double a; const char *delim = " \t"; @@ -609,14 +602,36 @@ argv += optind; if (argc == 0) { - ds[0] = ReadSet("-", column, delim); + setfilenames[0] = ""; + setfiles[0] = stdin; nds = 1; } else { if (argc > (MAX_DS - 1)) usage("Too many datasets."); nds = argc; - for (i = 0; i < nds; i++) - ds[i] = ReadSet(argv[i], column, delim); + for (i = 0; i < nds; i++) { + setfilenames[i] = argv[i]; + setfiles[i] = fopen(argv[i], "r"); + if (setfiles[i] == NULL) + err(2, "Cannot open %s", argv[i]); + } + } + + if (caph_limit_stdio() < 0) + err(2, "capsicum"); + + for (i = 0; i < nds; i++) + if (caph_limit_stream(fileno(setfiles[i]), CAPH_READ) < 0) + err(2, "unable to limit rights for %s", + setfilenames[i]); + + /* Enter Capsicum sandbox. */ + if (cap_enter() < 0 && errno != ENOSYS) + err(2, "unable to enter capability mode"); + + for (i = 0; i < nds; i++) { + ds[i] = ReadSet(setfiles[i], setfilenames[i], column, delim); + fclose(setfiles[i]); } for (i = 0; i < nds; i++)