#include <stdio.h>
#include <string.h>
#include <errno.h>
+#include <limits.h>
#include "nscd.h"
static const struct {
int32_t req_buf[REQ_LEN] = {
NSCDVERSION,
req,
- strlen(key)+1
+ strnlen(key,LOGIN_NAME_MAX)+1
};
struct msghdr msg = {
.msg_iov = (struct iovec[]){
},
.msg_iovlen = 2
};
+ int errno_save = errno;
*swap = 0;
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;
}