summaryrefslogtreecommitdiff
path: root/libc/pwd_grp/__getspent_r.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-06-27 10:19:29 +0000
committerEric Andersen <andersen@codepoet.org>2003-06-27 10:19:29 +0000
commit2e55dec21f3310e6868689fc1f4c4074ea3a35bb (patch)
tree77479d130301a86ca26009cf712dc0ebe3ddd340 /libc/pwd_grp/__getspent_r.c
parentea3abe244d9ad2ec59d00b29152fc457571d2d37 (diff)
Fixup errno handling
-Erik
Diffstat (limited to 'libc/pwd_grp/__getspent_r.c')
-rw-r--r--libc/pwd_grp/__getspent_r.c10
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;