commit-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[hurd] 13/87: Fix buffer allocation on io_read


From: Samuel Thibault
Subject: [hurd] 13/87: Fix buffer allocation on io_read
Date: Sun, 09 Nov 2014 11:04:59 +0000

This is an automated email from the git hooks/post-receive script.

sthibault pushed a commit to branch upstream
in repository hurd.

commit 2e94e61f1c6263adfcbca641b74f9a07ea8298a0
Author: Samuel Thibault <address@hidden>
Date:   Fri May 30 20:21:54 2014 +0200

    Fix buffer allocation on io_read
    
    * random.c (trivfs_S_io_read): Catch buffer allocation error, and
    truncate allocation when we return less data than requested.
---
 random.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/random.c b/random.c
index 0ae31f5..666a371 100644
--- a/random.c
+++ b/random.c
@@ -152,6 +152,7 @@ trivfs_S_io_read (struct trivfs_protid *cred,
 
   if (amount > 0)
     {
+      mach_msg_type_number_t new_amount;
       while (readable_pool (amount, level) == 0)
        {
          if (cred->po->openmodes & O_NONBLOCK)
@@ -170,10 +171,22 @@ trivfs_S_io_read (struct trivfs_protid *cred,
 
       /* Possibly allocate a new buffer. */
       if (*data_len < amount)
-       *data = mmap (0, amount, PROT_READ|PROT_WRITE,
-                                    MAP_ANON, 0, 0);
-         
-      amount = read_pool ((byte *) *data, amount, level);
+       {
+         *data = mmap (0, amount, PROT_READ|PROT_WRITE,
+                                      MAP_ANON, 0, 0);
+         if (*data == MAP_FAILED)
+           {
+             pthread_mutex_unlock (&global_lock);
+             return errno;
+           }
+       }
+
+      new_amount = read_pool ((byte *) *data, amount, level);
+
+      if (new_amount < amount)
+       munmap (*data + round_page (new_amount),
+               round_page(amount) - round_page (new_amount));
+      amount = new_amount;
     }
   *data_len = amount;
 

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-hurd/hurd.git



reply via email to

[Prev in Thread] Current Thread [Next in Thread]