getservbyport_r: fix out-of-bounds buffer read
[musl] / src / passwd / getpwent.c
index dabd411..f2bd516 100644 (file)
@@ -1,6 +1,9 @@
 #include "pwf.h"
 
 static FILE *f;
+static char *line;
+static struct passwd pw;
+static size_t size;
 
 void setpwent()
 {
@@ -12,28 +15,23 @@ weak_alias(setpwent, endpwent);
 
 struct passwd *getpwent()
 {
-       static char *line;
-       static struct passwd pw;
-       size_t size=0;
-       if (!f) f = fopen("/etc/passwd", "rb");
+       struct passwd *res;
+       if (!f) f = fopen("/etc/passwd", "rbe");
        if (!f) return 0;
-       return __getpwent_a(f, &pw, &line, &size);
+       __getpwent_a(f, &pw, &line, &size, &res);
+       return res;
 }
 
 struct passwd *getpwuid(uid_t uid)
 {
-       struct passwd *pw;
-       setpwent();
-       while ((pw=getpwent()) && pw->pw_uid != uid);
-       endpwent();
-       return pw;
+       struct passwd *res;
+       __getpw_a(0, uid, &pw, &line, &size, &res);
+       return res;
 }
 
 struct passwd *getpwnam(const char *name)
 {
-       struct passwd *pw;
-       setpwent();
-       while ((pw=getpwent()) && strcmp(pw->pw_name, name));
-       endpwent();
-       return pw;
+       struct passwd *res;
+       __getpw_a(name, 0, &pw, &line, &size, &res);
+       return res;
 }