diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2015-04-24 17:34:58 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2015-04-24 17:34:58 +0000 |
commit | 15aaa7114861f523a930e03e818efa68b9170ec2 (patch) | |
tree | 170f6586e22ab214f63610d96c9a1b664d47390b /usr.bin/file/file.c | |
parent | 8d3f0d1f65196262cb81c901b2e5186b49493529 (diff) |
Do not attempt to use ~/.magic if running as root (or issetugid()).
Diffstat (limited to 'usr.bin/file/file.c')
-rw-r--r-- | usr.bin/file/file.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/usr.bin/file/file.c b/usr.bin/file/file.c index eaf2072f7ad..02f5f24296d 100644 --- a/usr.bin/file/file.c +++ b/usr.bin/file/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.31 2015/04/24 17:10:50 nicm Exp $ */ +/* $OpenBSD: file.c,v 1.32 2015/04/24 17:34:57 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org> @@ -137,23 +137,25 @@ main(int argc, char **argv) } else if (argc == 0) usage(); - home = getenv("HOME"); - if (home == NULL || *home == '\0') { - pw = getpwuid(getuid()); - if (pw != NULL) - home = pw->pw_dir; - else - home = NULL; + f = NULL; + if (geteuid() != 0 && !issetugid()) { + home = getenv("HOME"); + if (home == NULL || *home == '\0') { + pw = getpwuid(getuid()); + if (pw != NULL) + home = pw->pw_dir; + else + home = NULL; + } + if (home != NULL) { + xasprintf(&path, "%s/.magic", home); + f = fopen(path, "r"); + if (f == NULL && errno != ENOENT) + err(1, "%s", path); + if (f == NULL) + free(path); + } } - if (home != NULL) { - xasprintf(&path, "%s/.magic", home); - f = fopen(path, "r"); - if (f == NULL && errno != ENOENT) - err(1, "%s", path); - if (f == NULL) - free(path); - } else - f = NULL; if (f == NULL) { path = xstrdup("/etc/magic"); f = fopen(path, "r"); |