summaryrefslogtreecommitdiff
path: root/nscd/initgrcache.c
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@suse.de>2012-12-04 16:14:13 +0100
committerAndreas Schwab <schwab@suse.de>2013-04-15 10:33:52 +0200
commit306dfba9e1daac21ab5a45256b367aea9cf9c3ee (patch)
tree733e50d1d866af426cab811c4527733bc1eb4eeb /nscd/initgrcache.c
parent206a6699116215c591c8562c67106f7e17146608 (diff)
downloadglibc-306dfba9e1daac21ab5a45256b367aea9cf9c3ee.tar.gz
Properly check for short writes when sending the response in nscd
Diffstat (limited to 'nscd/initgrcache.c')
-rw-r--r--nscd/initgrcache.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/nscd/initgrcache.c b/nscd/initgrcache.c
index 196407c870..462780e624 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, &notfound, total,
- MSG_NOSIGNAL));
+ if (fd != -1
+ && TEMP_FAILURE_RETRY (send (fd, &notfound, 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__,