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

Re: [PATCH] Fix off-by-one errors in read.



Looks ok,

Regards,

Hans


On 05/27/2009 07:49 PM, Bill Nottingham wrote:
Only read in 63 bytes, to make sure we preserve any trailing NULs for
end of string.

Signed-off-by: Bill Nottingham<notting redhat com>
---
  isys/devices.c |    8 ++++----
  1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/isys/devices.c b/isys/devices.c
index 1efff62..98c8769 100644
--- a/isys/devices.c
+++ b/isys/devices.c
@@ -68,7 +68,7 @@ struct device **getDevices(enum deviceType type) {
              fd = open(path, O_RDONLY);
              if (fd == -1)
                  continue;
-            if (read(fd, buf, 64)<= 0) {
+            if (read(fd, buf, 63)<= 0) {
                  close(fd);
                  continue;
              }
@@ -97,7 +97,7 @@ struct device **getDevices(enum deviceType type) {

                  if (fd == -1)
                      continue;
-                if (read(fd, buf, 64)<= 0) {
+                if (read(fd, buf, 63)<= 0) {
                      close(fd);
                      continue;
                  }
@@ -155,7 +155,7 @@ storagedone:
              fd = open(path, O_RDONLY);
              if (fd == -1)
                  continue;
-            if (read(fd, buf, 64)<= 0) {
+            if (read(fd, buf, 63)<= 0) {
                  close(fd);
                  continue;
              }
@@ -179,7 +179,7 @@ storagedone:
              fd = open(path, O_RDONLY);
              if (fd != -1) {
                  memset(buf, '\0', 64);
-                if (read(fd, buf, 64)>  0) {
+                if (read(fd, buf, 63)>  0) {
                      int i;
                      for (i = (strlen(buf)-1); isspace(buf[i]); i--)
                          buf[i] = '\0';


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