man/man-db-2.6.3-security4.dif
2012-10-02 17:06:04 +00:00

49 lines
1.4 KiB
Plaintext

--- src/mandb.c
+++ src/mandb.c 2012-10-01 14:30:11.619507260 +0000
@@ -37,6 +37,7 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h> /* for chmod() */
+#include <fcntl.h> /* for open () */
#include <dirent.h>
#include <unistd.h>
#include <signal.h>
@@ -420,11 +421,20 @@ static int mandb (const char *catpath, c
char *dbname;
char *cachedir_tag;
struct stat st;
+ int fd;
dbname = mkdbname (catpath);
sprintf (pid, "%d", getpid ());
database = appendstr (NULL, catpath, "/", pid, NULL);
-
+
+ /* Just for the case that catpath isn't a system catpath */
+ drop_effective_privs ();
+ fd = open (database, O_WRONLY | O_CREAT | O_EXCL, 0644);
+ regain_effective_privs ();
+ if (fd < 0)
+ error (FATAL, errno, _("can't create a temporary filename"));
+ close(fd);
+
if (!quiet)
printf (_("Processing manual pages under %s...\n"), manpath);
@@ -432,6 +442,7 @@ static int mandb (const char *catpath, c
if (stat (cachedir_tag, &st) == -1 && errno == ENOENT) {
FILE *cachedir_tag_file;
+ drop_effective_privs ();
cachedir_tag_file = fopen (cachedir_tag, "w");
if (cachedir_tag_file) {
fputs ("Signature: 8a477f597d28d172789f06886806bc55\n"
@@ -443,6 +454,7 @@ static int mandb (const char *catpath, c
cachedir_tag_file);
fclose (cachedir_tag_file);
}
+ regain_effective_privs ();
}
free (cachedir_tag);