diff options
Diffstat (limited to 'init')
| -rwxr-xr-x | init/util.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/init/util.c b/init/util.c index 13c9ca25..cb00f848 100755 --- a/init/util.c +++ b/init/util.c @@ -129,11 +129,23 @@ void *read_file(const char *fn, unsigned *_sz) char *data; int sz; int fd; + struct stat sb; data = 0; fd = open(fn, O_RDONLY); if(fd < 0) return 0; + // for security reasons, disallow world-writable + // or group-writable files + if (fstat(fd, &sb) < 0) { + ERROR("fstat failed for '%s'\n", fn); + goto oops; + } + if ((sb.st_mode & (S_IWGRP | S_IWOTH)) != 0) { + ERROR("skipping insecure file '%s'\n", fn); + goto oops; + } + sz = lseek(fd, 0, SEEK_END); if(sz < 0) goto oops; |
