about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-09-27 16:45:29 -0400
committerRich Felker <dalias@aerifal.cx>2011-09-27 16:45:29 -0400
commitaef84ca7ec87ed21c2a2d5eecf3b4bbd6cbe3db9 (patch)
tree8fec45826a94354abe12e973f89086bda52cc1f4
parent60164570111873175111cf8a5b973375e492eee9 (diff)
downloadmusl-aef84ca7ec87ed21c2a2d5eecf3b4bbd6cbe3db9.tar.gz
musl-aef84ca7ec87ed21c2a2d5eecf3b4bbd6cbe3db9.tar.xz
musl-aef84ca7ec87ed21c2a2d5eecf3b4bbd6cbe3db9.zip
fix clobbering of errno in get(pw|gr)([ug]id|nam) by fclose
-rw-r--r--src/passwd/getgrent.c6
-rw-r--r--src/passwd/getpwent.c6
2 files changed, 12 insertions, 0 deletions
diff --git a/src/passwd/getgrent.c b/src/passwd/getgrent.c
index e9d25eba..4cbe1ebf 100644
--- a/src/passwd/getgrent.c
+++ b/src/passwd/getgrent.c
@@ -23,17 +23,23 @@ struct group *getgrent()
 struct group *getgrgid(gid_t gid)
 {
 	struct group *gr;
+	int errno_saved;
 	setgrent();
 	while ((gr=getgrent()) && gr->gr_gid != gid);
+	errno_saved = errno;
 	endgrent();
+	errno = errno_saved;
 	return gr;
 }
 
 struct group *getgrnam(const char *name)
 {
 	struct group *gr;
+	int errno_saved;
 	setgrent();
 	while ((gr=getgrent()) && strcmp(gr->gr_name, name));
+	errno_saved = errno;
 	endgrent();
+	errno = errno_saved;
 	return gr;
 }
diff --git a/src/passwd/getpwent.c b/src/passwd/getpwent.c
index dabd411a..e8501461 100644
--- a/src/passwd/getpwent.c
+++ b/src/passwd/getpwent.c
@@ -23,17 +23,23 @@ struct passwd *getpwent()
 struct passwd *getpwuid(uid_t uid)
 {
 	struct passwd *pw;
+	int errno_saved;
 	setpwent();
 	while ((pw=getpwent()) && pw->pw_uid != uid);
+	errno_saved = errno;
 	endpwent();
+	errno = errno_saved;
 	return pw;
 }
 
 struct passwd *getpwnam(const char *name)
 {
 	struct passwd *pw;
+	int errno_saved;
 	setpwent();
 	while ((pw=getpwent()) && strcmp(pw->pw_name, name));
+	errno_saved = errno;
 	endpwent();
+	errno = errno_saved;
 	return pw;
 }