diff options
author | Andreas Schwab <schwab@suse.de> | 2012-12-04 16:14:13 +0100 |
---|---|---|
committer | Andreas Schwab <schwab@suse.de> | 2013-01-10 09:59:58 +0100 |
commit | dd31ac7a8e0d4cc24eee6815f9101caa5aa64291 (patch) | |
tree | 084cc65c5b744f23cada0fae9bfd4c0c1cbb3ca3 /nscd/servicescache.c | |
parent | 3167bfc62bb38e3057f7694566b5bb157236a5a8 (diff) | |
download | glibc-dd31ac7a8e0d4cc24eee6815f9101caa5aa64291.tar.gz |
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.
Diffstat (limited to 'nscd/servicescache.c')
-rw-r--r-- | nscd/servicescache.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/nscd/servicescache.c b/nscd/servicescache.c index d29cde7d63..b16f9e5866 100644 --- a/nscd/servicescache.c +++ b/nscd/servicescache.c @@ -65,6 +65,7 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req, const void *key, struct servent *serv, 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); @@ -290,14 +291,14 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req, { assert (db->wr_fd != -1); assert ((char *) &dataset->resp > (char *) db->data); - assert ((char *) &dataset->resp - (char *) db->head + assert ((char *) dataset - (char *) db->head + total <= (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, total); + - (char *) db->head, dataset->head.recsize); # ifndef __ASSUME_SENDFILE if (written == -1 && errno == ENOSYS) goto use_write; @@ -308,7 +309,10 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req, use_write: # endif #endif - written = writeall (fd, &dataset->resp, total); + written = writeall (fd, &dataset->resp, dataset->head.recsize); + + if (written != dataset->head.recsize) + all_written = false; } /* Add the record to the database. But only if it has not been @@ -332,7 +336,7 @@ cache_addserv (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__, |