more close-on-exec fixes, mostly using new "e" flag to fopen

This commit is contained in:
Rich Felker 2012-09-29 18:14:46 -04:00
commit d712dd396d
8 changed files with 9 additions and 9 deletions

View file

@ -438,7 +438,7 @@ static struct dso *load_library(const char *name)
if (fd < 0 && env_path) fd = path_open(name, env_path, buf, sizeof buf); if (fd < 0 && env_path) fd = path_open(name, env_path, buf, sizeof buf);
if (fd < 0) { if (fd < 0) {
if (!sys_path) { if (!sys_path) {
FILE *f = fopen(ETC_LDSO_PATH, "r"); FILE *f = fopen(ETC_LDSO_PATH, "rbe");
if (f) { if (f) {
if (getline(&sys_path, (size_t[1]){0}, f) > 0) if (getline(&sys_path, (size_t[1]){0}, f) > 0)
sys_path[strlen(sys_path)-1]=0; sys_path[strlen(sys_path)-1]=0;

View file

@ -17,7 +17,7 @@ void endusershell(void)
void setusershell(void) void setusershell(void)
{ {
if (!f) f = fopen("/etc/shells", "rb"); if (!f) f = fopen("/etc/shells", "rbe");
if (!f) f = fmemopen((void *)defshells, sizeof defshells - 1, "rb"); if (!f) f = fmemopen((void *)defshells, sizeof defshells - 1, "rb");
} }

View file

@ -16,7 +16,7 @@ static int getgr_r(const char *name, gid_t gid, struct group *gr, char *buf, siz
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
f = fopen("/etc/group", "rb"); f = fopen("/etc/group", "rbe");
if (!f) { if (!f) {
rv = errno; rv = errno;
goto done; goto done;

View file

@ -15,7 +15,7 @@ struct group *getgrent()
static char *line, **mem; static char *line, **mem;
static struct group gr; static struct group gr;
size_t size=0, nmem=0; size_t size=0, nmem=0;
if (!f) f = fopen("/etc/group", "rb"); if (!f) f = fopen("/etc/group", "rbe");
if (!f) return 0; if (!f) return 0;
return __getgrent_a(f, &gr, &line, &size, &mem, &nmem); return __getgrent_a(f, &gr, &line, &size, &mem, &nmem);
} }

View file

@ -13,7 +13,7 @@ static int getpw_r(const char *name, uid_t uid, struct passwd *pw, char *buf, si
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
f = fopen("/etc/passwd", "rb"); f = fopen("/etc/passwd", "rbe");
if (!f) { if (!f) {
rv = errno; rv = errno;
goto done; goto done;

View file

@ -15,7 +15,7 @@ struct passwd *getpwent()
static char *line; static char *line;
static struct passwd pw; static struct passwd pw;
size_t size=0; size_t size=0;
if (!f) f = fopen("/etc/passwd", "rb"); if (!f) f = fopen("/etc/passwd", "rbe");
if (!f) return 0; if (!f) return 0;
return __getpwent_a(f, &pw, &line, &size); return __getpwent_a(f, &pw, &line, &size);
} }

View file

@ -46,7 +46,7 @@ int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t size, struct
if (snprintf(path, sizeof path, "/etc/tcb/%s/shadow", name) >= sizeof path) if (snprintf(path, sizeof path, "/etc/tcb/%s/shadow", name) >= sizeof path)
return EINVAL; return EINVAL;
fd = open(path, O_RDONLY|O_NOFOLLOW|O_NONBLOCK); fd = open(path, O_RDONLY|O_NOFOLLOW|O_NONBLOCK|O_CLOEXEC);
if (fd >= 0) { if (fd >= 0) {
struct stat st = { 0 }; struct stat st = { 0 };
errno = EINVAL; errno = EINVAL;
@ -57,7 +57,7 @@ int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t size, struct
return errno; return errno;
} }
} else { } else {
f = fopen("/etc/shadow", "rb"); f = fopen("/etc/shadow", "rbe");
if (!f) return errno; if (!f) return errno;
} }

View file

@ -22,7 +22,7 @@ struct tm *getdate(const char *s)
goto out; goto out;
} }
f = fopen(datemsk, "r"); f = fopen(datemsk, "rbe");
if (!f) { if (!f) {
if (errno == ENOMEM) getdate_err = 6; if (errno == ENOMEM) getdate_err = 6;
else getdate_err = 2; else getdate_err = 2;