Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F105975340
D7925.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D7925.diff
View Options
Index: head/usr.bin/ministat/ministat.c
===================================================================
--- head/usr.bin/ministat/ministat.c
+++ head/usr.bin/ministat/ministat.c
@@ -11,16 +11,20 @@
#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 <capsicum_helpers.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
@@ -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 = "<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;
@@ -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] = "<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]);
+ }
+ }
+
+ 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++)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 24, 8:23 AM (19 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15587363
Default Alt Text
D7925.diff (2 KB)
Attached To
Mode
D7925: ministat(1): Capsicumify
Attached
Detach File
Event Timeline
Log In to Comment