From dd31ac7a8e0d4cc24eee6815f9101caa5aa64291 Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Tue, 4 Dec 2012 16:14:13 +0100 Subject: Properly check for short writes when sending the response in nscd * nscd/grpcache.c (cache_addgr): Properly check for short write. * nscd/initgrcache.c (addinitgroupsX): Likewise. * nscd/pwdcache.c (cache_addpw): Likewise. * nscd/servicescache.c (cache_addserv): Likewise. Don't write more than recsize. --- nscd/pwdcache.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'nscd/pwdcache.c') diff --git a/nscd/pwdcache.c b/nscd/pwdcache.c index ef492b5..bfc1831 100644 --- a/nscd/pwdcache.c +++ b/nscd/pwdcache.c @@ -81,6 +81,7 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req, const void *key, struct passwd *pwd, uid_t owner, struct hashentry *const he, struct datahead *dh, int errval) { + bool all_written = true; ssize_t total; ssize_t written; time_t t = time (NULL); @@ -306,7 +307,7 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req, + db->head->data_size)); written = sendfileall (fd, db->wr_fd, (char *) &dataset->resp - - (char *) db->head, dataset->head.recsize ); + - (char *) db->head, dataset->head.recsize); # ifndef __ASSUME_SENDFILE if (written == -1 && errno == ENOSYS) goto use_write; @@ -318,6 +319,9 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req, # endif #endif written = writeall (fd, &dataset->resp, dataset->head.recsize); + + if (written != dataset->head.recsize) + all_written = false; } @@ -377,7 +381,7 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req, } } - if (__builtin_expect (written != total, 0) && debug_level > 0) + if (__builtin_expect (!all_written, 0) && debug_level > 0) { char buf[256]; dbg_log (_("short write in %s: %s"), __FUNCTION__, -- cgit v1.1