summaryrefslogtreecommitdiff
blob: 9cd120eddb598f399bcb39fd6d39daeabb95317a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
--- playmidi.c.orig	2005-01-17 17:43:20.578060936 -0500
+++ playmidi.c	2005-01-17 17:48:55.022217696 -0500
@@ -22,6 +22,7 @@
 #include <ctype.h>
 #include <unistd.h>
 #include <sys/stat.h>
+#include <errno.h>
 #include "playmidi.h"
 
 SEQ_DEFINEBUF(SEQUENCERBLOCKSIZE);
@@ -186,6 +187,15 @@
     struct stat info;
     int piped = 0;
 
+    /* CPhipps 2000/02/04 - this might be splaymidi, in which case we're
+     * probably setuid root. Drop privs immediately.. io_svgalib.c can
+     * regain them */
+    if (getuid() != geteuid())
+       if (seteuid(getuid())) {
+           perror("seteuid");
+           exit(EPERM); /* Seems appropriate */
+       }
+
     printf("%s Copyright (C) 1994-1997 Nathan I. Laredo,"
 	   " AWE32 by Takashi Iwai\n"
 	   "This is free software with ABSOLUTELY NO WARRANTY.\n"
@@ -439,9 +449,9 @@
     for (i = optind; i < argc;) {
 	filename = argv[i];
 	if (stat(filename, &info) == -1) {
-	    if ((extra = malloc(strlen(filename) + 4)) == NULL)
+	    if ((extra = malloc(strlen(filename) + 5)) == NULL)
 		close_show(-1);
-	    sprintf(extra, "%s.mid", filename);
+	    snprintf(extra, sizeof(extra), "%s.mid", filename);
 	    if (stat(extra, &info) == -1)
 		close_show(-1);
 	    if ((mfd = fopen(extra, "r")) == NULL)
@@ -452,7 +462,7 @@
 	    if (ext && strcmp(ext, ".gz") == 0) {
 		char temp[1024];
 		piped = 1;
-		sprintf(temp, "gzip -l %s", filename);
+		snprintf(temp, sizeof(temp), "gzip -l %s", filename);
 		if ((mfd = popen(temp, "r")) == NULL)
 		    close_show(-1);
 		fgets(temp, sizeof(temp), mfd); /* skip 1st line */
@@ -460,7 +470,7 @@
 		strtok(temp, " "); /* compressed size */
 		info.st_size = atoi(strtok(NULL, " ")); /* original size */
 		pclose(mfd);
-		sprintf(temp, "gzip -d -c %s", filename);
+		snprintf(temp, sizeof(temp), "gzip -d -c %s", filename);
 		if ((mfd = popen(temp, "r")) == NULL)
 		    close_show(-1);
 	    } else if ((mfd = fopen(filename, "r")) == NULL)
--- io_svgalib.c.orig	2005-01-17 17:49:55.758984304 -0500
+++ io_svgalib.c	2005-01-17 17:49:59.310444400 -0500
@@ -259,6 +259,10 @@
     tcgetattr(mytty, &newtty);
     newtty.c_lflag &= ~(ICANON | ECHO | ICRNL | ISIG);
     tcsetattr(mytty, TCSANOW, &newtty);
+    /* CPhipps 2000/02/04 - restore euid root in order to start SVGALib.
+     * We don't have to worry about errors, or dropping priv's afterwards,
+     * SVGALib handles that safely for us. */
+    seteuid(0);
     vga_init();
     if ((vgamode = vga_getdefaultmode()) == -1)
 	vgamode = G640x480x256;