X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fpasswd%2Fnscd_query.c;h=d38e371bcda395855a4e9a125d4a75a115c76416;hb=0847902ab99065a48f9bd3729b6e676288dfd69e;hp=55ccc0a81954db0b58a7a26a203f5d98cafb9b4f;hpb=49d1e7f93129cdcc2ab0cc91832b8a29ccd1570d;p=musl diff --git a/src/passwd/nscd_query.c b/src/passwd/nscd_query.c index 55ccc0a8..d38e371b 100644 --- a/src/passwd/nscd_query.c +++ b/src/passwd/nscd_query.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "nscd.h" static const struct { @@ -22,7 +23,7 @@ FILE *__nscd_query(int32_t req, const char *key, int32_t *buf, size_t len, int * int32_t req_buf[REQ_LEN] = { NSCDVERSION, req, - strlen(key)+1 + strnlen(key,LOGIN_NAME_MAX)+1 }; struct msghdr msg = { .msg_iov = (struct iovec[]){ @@ -31,6 +32,7 @@ FILE *__nscd_query(int32_t req, const char *key, int32_t *buf, size_t len, int * }, .msg_iovlen = 2 }; + int errno_save = errno; *swap = 0; retry: @@ -45,15 +47,18 @@ retry: return 0; } - if (strlen(key) > INT32_MAX - 1) + if (req_buf[2] > LOGIN_NAME_MAX) return f; if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) { - /* If there isn't a running nscd we return -1 to indicate that - * that is precisely what happened - */ - if (errno == EACCES || errno == ECONNREFUSED || errno == ENOENT) + /* If there isn't a running nscd we simulate a "not found" + * result and the caller is responsible for calling + * fclose on the (unconnected) socket. The value of + * errno must be left unchanged in this case. */ + if (errno == EACCES || errno == ECONNREFUSED || errno == ENOENT) { + errno = errno_save; return f; + } goto error; }