From 306dfba9e1daac21ab5a45256b367aea9cf9c3ee 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/initgrcache.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'nscd/initgrcache.c') diff --git a/nscd/initgrcache.c b/nscd/initgrcache.c index 196407c..462780e 100644 --- a/nscd/initgrcache.c +++ b/nscd/initgrcache.c @@ -171,15 +171,16 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req, nip = nip->next; } + bool all_written; ssize_t total; - ssize_t written; time_t timeout; out: + all_written = true; timeout = MAX_TIMEOUT_VALUE; if (!any_success) { /* Nothing found. Create a negative result record. */ - written = total = sizeof (notfound); + total = sizeof (notfound); if (he != NULL && all_tryagain) { @@ -197,9 +198,10 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req, { /* We have no data. This means we send the standard reply for this case. */ - if (fd != -1) - written = TEMP_FAILURE_RETRY (send (fd, ¬found, total, - MSG_NOSIGNAL)); + if (fd != -1 + && TEMP_FAILURE_RETRY (send (fd, ¬found, total, + MSG_NOSIGNAL)) != total) + all_written = false; /* If we have a transient error or cannot permanently store the result, so be it. */ @@ -251,8 +253,7 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req, else { - written = total = (offsetof (struct dataset, strdata) - + start * sizeof (int32_t)); + total = offsetof (struct dataset, strdata) + start * sizeof (int32_t); /* If we refill the cache, first assume the reconrd did not change. Allocate memory on the cache since it is likely @@ -365,20 +366,27 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req, <= (sizeof (struct database_pers_head) + db->head->module * sizeof (ref_t) + db->head->data_size)); - written = sendfileall (fd, db->wr_fd, - (char *) &dataset->resp - - (char *) db->head, dataset->head.recsize); + ssize_t written = sendfileall (fd, db->wr_fd, + (char *) &dataset->resp + - (char *) db->head, + dataset->head.recsize); + if (written != dataset->head.recsize) + { # ifndef __ASSUME_SENDFILE - if (written == -1 && errno == ENOSYS) - goto use_write; + if (written == -1 && errno == ENOSYS) + goto use_write; # endif + all_written = false; + } } else # ifndef __ASSUME_SENDFILE use_write: # endif #endif - written = writeall (fd, &dataset->resp, dataset->head.recsize); + if (writeall (fd, &dataset->resp, dataset->head.recsize) + != dataset->head.recsize) + all_written = false; } @@ -405,7 +413,7 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req, free (groups); - 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