This is a note to let you know that I've just added the patch titled

    tools/hv: Check for read/write errors

to the 3.4-stable tree which can be found at:
    
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     tools-hv-check-for-read-write-errors.patch
and it can be found in the queue-3.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <[email protected]> know about it.


>From 436473bc2173499ae274d0f50111d1e355006caf Mon Sep 17 00:00:00 2001
From: Ben Hutchings <[email protected]>
Date: Wed, 5 Sep 2012 14:37:37 -0700
Subject: tools/hv: Check for read/write errors

From: Ben Hutchings <[email protected]>

commit 436473bc2173499ae274d0f50111d1e355006caf upstream.

hv_kvp_daemon currently does not check whether fread() or fwrite()
succeed.  Add the necessary checks.  Also, remove the incorrect use of
feof() before fread().

Signed-off-by: Ben Hutchings <[email protected]>
Signed-off-by: K. Y. Srinivasan <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

---
 tools/hv/hv_kvp_daemon.c |   22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -144,7 +144,12 @@ static void kvp_update_file(int pool)
                                sizeof(struct kvp_record),
                                kvp_file_info[pool].num_records, filep);
 
-       fclose(filep);
+       if (ferror(filep) || fclose(filep)) {
+               kvp_release_lock(pool);
+               syslog(LOG_ERR, "Failed to write file, pool: %d", pool);
+               exit(EXIT_FAILURE);
+       }
+
        kvp_release_lock(pool);
 }
 
@@ -165,12 +170,17 @@ static void kvp_update_mem_state(int poo
                syslog(LOG_ERR, "Failed to open file, pool: %d", pool);
                exit(EXIT_FAILURE);
        }
-       while (!feof(filep)) {
+       for (;;) {
                readp = &record[records_read];
                records_read += fread(readp, sizeof(struct kvp_record),
                                        ENTRIES_PER_BLOCK * num_blocks,
                                        filep);
 
+               if (ferror(filep)) {
+                       syslog(LOG_ERR, "Failed to read file, pool: %d", pool);
+                       exit(EXIT_FAILURE);
+               }
+
                if (!feof(filep)) {
                        /*
                         * We have more data to read.
@@ -233,12 +243,18 @@ static int kvp_file_init(void)
                        fclose(filep);
                        return 1;
                }
-               while (!feof(filep)) {
+               for (;;) {
                        readp = &record[records_read];
                        records_read += fread(readp, sizeof(struct kvp_record),
                                        ENTRIES_PER_BLOCK,
                                        filep);
 
+                       if (ferror(filep)) {
+                               syslog(LOG_ERR, "Failed to read file, pool: %d",
+                                      i);
+                               exit(EXIT_FAILURE);
+                       }
+
                        if (!feof(filep)) {
                                /*
                                 * We have more data to read.


Patches currently in stable-queue which might be from [email protected] are

queue-3.4/staging-speakup_soft-fix-reading-of-init-string.patch
queue-3.4/tools-hv-check-for-read-write-errors.patch
queue-3.4/tools-hv-fix-file-handle-leak.patch
queue-3.4/tools-hv-fix-exit-error-code.patch
--
To unsubscribe from this list: send the line "unsubscribe stable" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to