summaryrefslogtreecommitdiff
path: root/stagit.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2017-11-10 20:55:20 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2017-11-10 20:55:20 +0100
commit26bd89f681b631ce3596148c9320c3208e16f8e9 (patch)
treebaf0f6b7f7399880220849a28afcd69a2e777cc2 /stagit.c
parent1bab6952c6dcac50e66418f117032bb0f627d559 (diff)
fix file permissions for cachefile and respect umask(2)
Diffstat (limited to 'stagit.c')
-rw-r--r--stagit.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/stagit.c b/stagit.c
index 43cd2ef..bf027f6 100644
--- a/stagit.c
+++ b/stagit.c
@@ -1,4 +1,5 @@
#include <sys/stat.h>
+#include <sys/types.h>
#include <err.h>
#include <errno.h>
@@ -995,6 +996,7 @@ main(int argc, char *argv[])
git_object *obj = NULL;
const git_oid *head = NULL;
const git_error *e = NULL;
+ mode_t mask;
FILE *fp, *fpread;
char path[PATH_MAX], repodirabs[PATH_MAX + 1], *p;
char tmppath[64] = "cache.XXXXXXXXXXXX", buf[BUFSIZ];
@@ -1165,8 +1167,14 @@ main(int argc, char *argv[])
fclose(fp);
/* rename new cache file on success */
- if (cachefile && rename(tmppath, cachefile))
- err(1, "rename: '%s' to '%s'", tmppath, cachefile);
+ if (cachefile) {
+ if (rename(tmppath, cachefile))
+ err(1, "rename: '%s' to '%s'", tmppath, cachefile);
+ umask((mask = umask(0)));
+ if (chmod(cachefile,
+ (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) & ~mask))
+ err(1, "chmod: '%s'", cachefile);
+ }
/* cleanup */
git_repository_free(repo);