aboutsummaryrefslogtreecommitdiff
path: root/recipes/termcap/termcap-2.0.8/002_all_termcap-setuid.patch
blob: d881dae6c8367dc76cb62e8f0da2e50ea21dc8da (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
--- termcap-2.0.8/termcap.c~
+++ termcap-2.0.8/termcap.c
@@ -339,13 +339,17 @@
   struct tc_ent *l = NULL;
   int first = 1;
   int loop = 0;
+  int tc_set = 0;

   *tcp = NULL;

   /* See if we have a TERMCAP environment variable. */
   if ((tc = getenv("TERMCAP")) != NULL) {
	if (*tc == '/')
+	{
		tc_file = tc;
+		tc_set=1;
+	}
	else {
		/* check if TERMCAP is term */
		if (tc_comp(tc, term)) {
@@ -366,8 +370,21 @@
   printf("Using file %s\n", tc_file);
 #endif

+  if(tc_set)
+  {
+  	setfsuid(getuid());
+  	setfsgid(getgid());
+  }
   /* Now read the termcap file. */
-  if ((fp = fopen(tc_file, "r")) == NULL) return(NULL);
+  fp = fopen(tc_file, "r");
+
+  if(tc_set)
+  {
+  	setfsuid(geteuid());
+  	setfsgid(getegid());
+  }
+  if (fp == NULL)
+  	return(NULL);

   while(term) {
	if (++loop > 16) {