ncurses (5.7+20100313-5) 03-linux-use-fsuid.diff

Summary

 ncurses/tinfo/read_termcap.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

    
download this patch

Patch contents

---
 ncurses/tinfo/read_termcap.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

--- a/ncurses/tinfo/read_termcap.c
+++ b/ncurses/tinfo/read_termcap.c
@@ -319,6 +319,7 @@
 	     */
 	    if (fd >= 0) {
 		(void) lseek(fd, (off_t) 0, SEEK_SET);
+#ifndef __linux__
 	    } else if ((_nc_access(db_array[current], R_OK) < 0)
 		       || (fd = open(db_array[current], O_RDONLY, 0)) < 0) {
 		/* No error on unfound file. */
@@ -329,6 +330,33 @@
 	    } else {
 		myfd = TRUE;
 	    }
+#else
+	    } else {
+		bool fd1, fd2;
+
+		setfsuid(getuid());
+		setfsgid(getgid());
+
+		fd1 = _nc_access(db_array[current], R_OK) < 0;
+		if (!fd1) {
+		    fd = open(db_array[current], O_RDONLY, 0));
+		    fd1 = fd < 0;
+		}
+
+		setfsuid(geteuid());
+		setfsgid(getegid());
+
+		if (! fd1) {
+		    /* No error on unfound file. */
+		    if (errno == ENOENT)
+			continue;
+		    free(record);
+		    return (TC_SYS_ERR);
+		} else {
+		    myfd = TRUE;
+		}
+	    }
+#endif
 	    lineno = 0;
 
 	    /*
@@ -1097,8 +1125,20 @@
 	for (i = 0; i < filecount; i++) {
 
 	    T(("Looking for %s in %s", tn, termpaths[i]));
+#ifndef __linux__
 	    if (_nc_access(termpaths[i], R_OK) == 0
 		&& (fp = fopen(termpaths[i], "r")) != (FILE *) 0) {
+#else
+	    fp = (FILE *) 0;
+	    if (_nc_access(termpaths[i], R_OK) == 0) {
+		setfsuid(getuid());
+		setfsgid(getgid());
+		fp = fopen(termpaths[i], "r");
+		setfsuid(geteuid());
+		setfsgid(getegid());
+	    }
+	    if (fp != (FILE *) 0) {
+#endif
 		_nc_set_source(termpaths[i]);
 
 		/*