Page MenuHomeFreeBSD

D7925.id20423.diff
No OneTemporary

D7925.id20423.diff

Index: usr.bin/ministat/ministat.c
===================================================================
--- usr.bin/ministat/ministat.c
+++ usr.bin/ministat/ministat.c
@@ -11,16 +11,19 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <stdio.h>
-#include <math.h>
+#include <sys/capsicum.h>
+#include <sys/ioctl.h>
+#include <sys/queue.h>
+#include <sys/ttycom.h>
+
#include <ctype.h>
#include <err.h>
-#include <string.h>
+#include <errno.h>
+#include <math.h>
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/queue.h>
-#include <sys/ttycom.h>
#define NSTUDENT 100
#define NCONF 6
@@ -449,26 +452,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 = "<stdin>";
- } else if (!strcmp(n, "-")) {
- f = stdin;
- n = "<stdin>";
- } else {
- f = fopen(n, "r");
- }
- if (f == NULL)
- err(1, "Cannot open %s", n);
s = NewSet();
s->name = strdup(n);
line = 0;
@@ -493,7 +484,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);
@@ -530,7 +520,10 @@
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];
+ cap_rights_t rights;
int nds;
double a;
const char *delim = " \t";
@@ -603,14 +596,41 @@
argv += optind;
if (argc == 0) {
- ds[0] = ReadSet("-", column, delim);
+ setfilenames[0] = "<stdin>";
+ 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]);
+ }
+ }
+
+ cap_rights_init(&rights, CAP_FSTAT, CAP_WRITE);
+ if (cap_rights_limit(STDOUT_FILENO, &rights) < 0 && errno != ENOSYS)
+ err(2, "unable to limit rights for stdout");
+ if (cap_rights_limit(STDERR_FILENO, &rights) < 0 && errno != ENOSYS)
+ err(2, "unable to limit rights for stderr");
+
+ cap_rights_init(&rights, CAP_FSTAT, CAP_READ);
+ for (i = 0; i < nds; i++)
+ if (cap_rights_limit(fileno(setfiles[i]), &rights) < 0 &&
+ errno != ENOSYS)
+ 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++)

File Metadata

Mime Type
text/plain
Expires
Tue, Feb 10, 12:25 PM (13 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28623488
Default Alt Text
D7925.id20423.diff (2 KB)

Event Timeline