diff options
Diffstat (limited to 'libc/pwd_grp/__getspent_r.c')
-rw-r--r-- | libc/pwd_grp/__getspent_r.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/libc/pwd_grp/__getspent_r.c b/libc/pwd_grp/__getspent_r.c index 7150520d2..73e40f031 100644 --- a/libc/pwd_grp/__getspent_r.c +++ b/libc/pwd_grp/__getspent_r.c @@ -20,6 +20,7 @@ #include <unistd.h> #include <string.h> #include <fcntl.h> +#include <errno.h> #include "config.h" @@ -28,11 +29,14 @@ int __getspent_r(struct spwd * spwd, char * line_buff, size_t buflen, int spwd_f char *endptr; int line_len; + if (buflen<PWD_BUFFER_SIZE) + return ERANGE; + /* We use the restart label to handle malformatted lines */ restart: /* Read the shadow line into the buffer using a minimum of syscalls. */ if ((line_len = read(spwd_fd, line_buff, buflen)) <= 0) - return -1; + return EIO; endptr = strchr(line_buff, '\n'); if (endptr != NULL) lseek(spwd_fd, (long) (1 + endptr - (line_buff + line_len)), SEEK_CUR); @@ -40,13 +44,13 @@ restart: /* The line is too long - skip it. :-\ */ do { if ((line_len = read(spwd_fd, line_buff, buflen)) <= 0) - return -1; + return EIO; } while (!(endptr = strchr(line_buff, '\n'))); lseek(spwd_fd, (long) (endptr - line_buff) - line_len + 1, SEEK_CUR); goto restart; } - if (__sgetspent_r(line_buff, spwd, line_buff, buflen) < 0) + if (__sgetspent_r(line_buff, spwd, line_buff, buflen) != 0) goto restart; return 0; |